Class: Rack::AcceptHeaderUpdater

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ AcceptHeaderUpdater

Returns a new instance of AcceptHeaderUpdater.



51
52
53
# File 'lib/lane_groove.rb', line 51

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



55
56
57
58
59
60
61
62
63
64
# File 'lib/lane_groove.rb', line 55

def call(env)
  req = Rack::Request.new(env)
  if ext = (req.path_info.match('\.') && ".#{req.path_info.split('.').last}")
    if mime_type = Rack::Mime::MIME_TYPES[ext.downcase]
      env['HTTP_ACCEPT'] = [mime_type, env['HTTP_ACCEPT']].join(",")
      req.path_info.gsub!(/#{ext}$/, '')
    end
  end
  @app.call(env)
end