class Rack::ConditionalResponseHeaders

Constants

VERSION

Public Class Methods

new(app, conditions=[]) click to toggle source
# File lib/rack/conditional_response_headers.rb, line 7
def initialize(app, conditions=[])
  @app=app
  @conditions = conditions
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/conditional_response_headers.rb, line 12
def call(env)
  @status, @headers, @response = @app.call(env)
  @request = Rack::Request.new(env)
  [@status, _apply_headers, @response]
end

Private Instance Methods

_apply_headers() click to toggle source
# File lib/rack/conditional_response_headers.rb, line 20
def _apply_headers
  url =  @request.url
  @conditions.each do |item|
    condition = item[0] 
    if condition =~ @request.url
      headers = item[1]
      headers.each do |key, value|
        if value.nil?
          @headers.delete(key)
        else
          @headers[key] = value
        end
      end
    end
  end
  @headers
end