Class: Goliath::Rack::DefaultMimeType

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

Overview

Does some basic cleanup / handling of the HTTP_ACCEPT header. This will remove gzip, deflate, compressed and identity. If there are no values left the header will be set to */*.

Examples:

use Goliath::Rack::DefaultMimeType

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ DefaultMimeType

Returns a new instance of DefaultMimeType.



14
15
16
# File 'lib/goliath/rack/default_mime_type.rb', line 14

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
# File 'lib/goliath/rack/default_mime_type.rb', line 18

def call(env)
  accept = env['HTTP_ACCEPT'] || ''
  accept = accept.split(/\s*,\s*/)
  accept.delete_if { |a| a =~ /gzip|deflate|compressed|identity/ }
  accept = accept.join(", ")

  env['HTTP_ACCEPT'] = accept
  env['HTTP_ACCEPT'] = '*/*' if env['HTTP_ACCEPT'] == ''
  @app.call(env)
end