Class: SideBro::Web::Application
- Inherits:
-
Object
- Object
- SideBro::Web::Application
- Defined in:
- lib/side_bro/web/application.rb
Constant Summary collapse
- SAFE_METHODS =
%w[GET HEAD OPTIONS TRACE].freeze
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize ⇒ Application
constructor
A new instance of Application.
Constructor Details
#initialize ⇒ Application
Returns a new instance of Application.
10 11 12 13 14 |
# File 'lib/side_bro/web/application.rb', line 10 def initialize @router = SideBro::Web::Router.new register_routes register_extension_routes end |
Instance Method Details
#call(env) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/side_bro/web/application.rb', line 16 def call(env) unless SAFE_METHODS.include?(env["REQUEST_METHOD"]) unless env["HTTP_SEC_FETCH_SITE"] == "same-origin" return [403, {"Content-Type" => "text/plain"}, ["Forbidden"]] end end block = @router.match(env) return [404, {"Content-Type" => "text/plain"}, ["Not Found"]] unless block action = SideBro::Web::Action.new(env) catch(:halt) do action.instance_exec(&block) action.response.finish end end |