Class: AffiliationId::Middleware::Rack

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

Overview

Rack middleware to add Affiliation ID HTTP header to rack based web frameworks

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Rack

Returns a new instance of Rack.



11
12
13
# File 'lib/affiliation_id/middleware/rack.rb', line 11

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/affiliation_id/middleware/rack.rb', line 15

def call(env)
  AffiliationId.current_id = header_from_env(env) || AffiliationId.renew_current_id!

  @app.call(env).tap { |_status, headers, _body| headers[config.header_name] = AffiliationId.current_id }
ensure
  AffiliationId.reset!
end