Class: TurboBoost::Commands::EntryMiddleware

Inherits:
Object
  • Object
show all
Defined in:
lib/turbo_boost/commands/middlewares/entry_middleware.rb

Constant Summary collapse

PATH =
"/turbo-boost-command-invocation"
PARAM =
"turbo_boost_command"

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ EntryMiddleware

Returns a new instance of EntryMiddleware.



9
10
11
# File 'lib/turbo_boost/commands/middlewares/entry_middleware.rb', line 9

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/turbo_boost/commands/middlewares/entry_middleware.rb', line 13

def call(env)
  request = Rack::Request.new(env)

  # a command was not requested, pass through and exit early
  return @app.call(env) unless command_request?(request)

  # a command was requested
  return [403, {"Content-Type" => "text/plain"}, ["Forbidden"]] if untrusted_client?(request)
  modify_request!(request) if modify_request?(request)
  @app.call env
end