Class: Rack::RequestContext

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/request_context.rb

Overview

Public: Rack middleware that stores Rack Request in a thread local variable.

app - The Rack app.

Examples

use Rack::RequestContext

puts "Thread.current[:request_context].url"
# => 'https://www.remind101.com'

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RequestContext

Returns a new instance of RequestContext.



15
16
17
# File 'lib/rack/request_context.rb', line 15

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



19
20
21
22
23
24
25
# File 'lib/rack/request_context.rb', line 19

def call(env)
  env_dup = env.dup.freeze # make sure env var isn't modified
  ::RequestContext.request_context = Rack::Request.new(env_dup)
  @app.call(env)
ensure
  ::RequestContext.request_context = nil
end