Class: Rack::Headercontrol

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

Constant Summary collapse

VERSION =
"0.0.2"

Instance Method Summary collapse

Constructor Details

#initialize(app, &config_block) ⇒ Headercontrol

Returns a new instance of Headercontrol.



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

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

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rack/headercontrol.rb', line 10

def call(env)
  @app.call(env).tap do |response|
    @recorder = PathRecorder.new
    @config_block.call(@recorder)
    request = Rack::Request.new(env)
    response_headers = Utils::HeaderHash.new(response[1])
    @recorder.each do |condition, action|
      if request.path.match condition
        action.call(response_headers)
      end
    end
    response[1] = response_headers
  end
end