Class: Rack::RequestId

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/request_id.rb,
lib/rack-request-id/version.rb

Constant Summary collapse

VERSION =
"0.0.2"

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RequestId

Returns a new instance of RequestId.



5
6
7
# File 'lib/rack/request_id.rb', line 5

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
# File 'lib/rack/request_id.rb', line 9

def call(env)
  Thread.current[:request_id] = request.env['HTTP_X_REQUEST_ID'] || SecureRandom.hex(16)
  status, headers, body = @app.call(env)
  headers['X-Request-Id'] ||= Thread.current[:request_id]
  [status, headers, body]
end