Class: Rack::Acceptable::FakeAccept

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/acceptable/middleware/fake_accept.rb

Constant Summary collapse

ORIGINAL_HTTP_ACCEPT =
'rack-acceptable.fake_accept.original_HTTP_ACCEPT'

Instance Method Summary collapse

Constructor Details

#initialize(app, default_media = 'text/html') ⇒ FakeAccept

Returns a new instance of FakeAccept.



10
11
12
13
# File 'lib/rack/acceptable/middleware/fake_accept.rb', line 10

def initialize(app, default_media = 'text/html')
  @default_media = default_media
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/rack/acceptable/middleware/fake_accept.rb', line 15

def call(env)
  request = ::Rack::Request.new(env)
  extname = ::File.extname(request.path_info)
  env[ORIGINAL_HTTP_ACCEPT] = env[Const::ENV_HTTP_ACCEPT]
  env[Const::ENV_HTTP_ACCEPT] = Rack::Acceptable::MIMETypes.lookup(extname, @default_media)
  @app.call(env)
end