Class: Rack::ReplaceHttpAccept

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

Instance Method Summary collapse

Constructor Details

#initialize(app, replacements = {}) ⇒ ReplaceHttpAccept

Returns a new instance of ReplaceHttpAccept.



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

def initialize(app, replacements = {})
  @app = app
  @replacements = replacements
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
# File 'lib/rack/replace_http_accept.rb', line 10

def call(env)
  @replacements.each do |regex, replacement|
    if Regexp.new(regex).match(env.fetch('HTTP_ACCEPT', ''))
      env['HTTP_ACCEPT'] = replacement 
      break
    end
  end
  
  @app.call(env)
end