Class: Rack::ResponseHeaders
- Inherits:
-
Object
- Object
- Rack::ResponseHeaders
- Defined in:
- lib/rack/contrib/response_headers.rb
Overview
Allows you to tap into the response headers. Yields a Rack::Utils::HeaderHash (Rack 2) or a Rack::Headers (Rack 3) of current response headers to the block. Example:
use Rack::ResponseHeaders do |headers|
headers['X-Foo'] = 'bar'
headers.delete('X-Baz')
end
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, &block) ⇒ ResponseHeaders
constructor
A new instance of ResponseHeaders.
Constructor Details
#initialize(app, &block) ⇒ ResponseHeaders
Returns a new instance of ResponseHeaders.
17 18 19 20 |
# File 'lib/rack/contrib/response_headers.rb', line 17 def initialize(app, &block) @app = app @block = block end |
Instance Method Details
#call(env) ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/rack/contrib/response_headers.rb', line 22 def call(env) response = @app.call(env) headers = HEADERS_KLASS.new.merge(response[1]) @block.call(headers) response[1] = headers response end |