Class: Rack::ResponseHeaders

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

Overview

Allows you to tap into the response headers. Yields a Rack::Utils::HeaderHash 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

Constructor Details

#initialize(app, &block) ⇒ ResponseHeaders

Returns a new instance of ResponseHeaders.



11
12
13
14
# File 'lib/rack/contrib/response_headers.rb', line 11

def initialize(app, &block)
  @app = app
  @block = block
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/rack/contrib/response_headers.rb', line 16

def call(env)
  response = @app.call(env)
  headers = Utils::HeaderHash.new(response[1])
  @block.call(headers)
  response[1] = headers
  response
end