Class: Aikido::Zen::Middleware::SetContext

Inherits:
Object
  • Object
show all
Defined in:
lib/aikido/zen/middleware/set_context.rb

Overview

Rack middleware that keeps the current context in a Thread/Fiber-local variable so that other parts of the agent/firewall can access it.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ SetContext

Returns a new instance of SetContext.



13
14
15
# File 'lib/aikido/zen/middleware/set_context.rb', line 13

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/aikido/zen/middleware/set_context.rb', line 17

def call(env)
  context = Context.from_rack_env(env)

  Aikido::Zen.current_context = env[ENV_KEY] = context
  Aikido::Zen.track_request(context.request)

  @app.call(env)
ensure
  Aikido::Zen.current_context = nil
end