Class: Rackables::ResponseHeaders

Inherits:
Object
  • Object
show all
Defined in:
lib/rackables/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 Rackables::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.



13
14
15
16
# File 'lib/rackables/response_headers.rb', line 13

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

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
# File 'lib/rackables/response_headers.rb', line 18

def call(env)
  status, headers, body = @app.call(env)
  headers = ::Rack::Utils::HeaderHash.new(headers)
  @block.call(headers)
  [status, headers, body]
end