Class: Hyperdrive::Middleware::ContentNegotiation
- Inherits:
-
Object
- Object
- Hyperdrive::Middleware::ContentNegotiation
- Defined in:
- lib/hyperdrive/middleware/content_negotiation.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ ContentNegotiation
constructor
A new instance of ContentNegotiation.
Constructor Details
#initialize(app) ⇒ ContentNegotiation
Returns a new instance of ContentNegotiation.
6 7 8 |
# File 'lib/hyperdrive/middleware/content_negotiation.rb', line 6 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/hyperdrive/middleware/content_negotiation.rb', line 10 def call(env) accept = env['hyperdrive.accept'] acceptable_content_types = env['hyperdrive.resource'].acceptable_content_types(env['REQUEST_METHOD']) env['hyperdrive.media_type'] = accept.best_of(acceptable_content_types) raise Hyperdrive::Errors::NotAcceptable.new(env['HTTP_ACCEPT']) unless env['hyperdrive.media_type'] @app.call(env) end |