Class: Rack::SupportedMediaTypes

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

Instance Method Summary collapse

Constructor Details

#initialize(app, mime_types) ⇒ SupportedMediaTypes

Returns a new instance of SupportedMediaTypes.



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

def initialize(app, mime_types)
  @app, @mime_types = app, mime_types
end

Instance Method Details

#call(env) ⇒ Object

– return any headers with 406?



12
13
14
15
16
17
# File 'lib/rack/supported_media_types.rb', line 12

def call(env)
  req_type = accept(env)
  !req_type.empty? && @mime_types.any? {|type| type.match(/#{req_type}/) } ?
    @app.call(env) :
    Rack::Response.new([], 406).finish
end