lib/grape/middleware/base.rb in grape-0.2.3 vs lib/grape/middleware/base.rb in grape-0.2.4
- old
+ new
@@ -1,6 +1,7 @@
require 'active_support/ordered_hash'
+require 'active_support/core_ext/hash/indifferent_access'
require 'multi_json'
require 'multi_xml'
module Grape
module Middleware
@@ -22,11 +23,13 @@
def initialize(app, options = {})
@app = app
@options = default_options.merge(options)
end
- def default_options; {} end
+ def default_options
+ {}
+ end
def call(env)
dup.call!(env)
end
@@ -51,15 +54,19 @@
def response
Rack::Response.new(@app_response)
end
+ def content_type_for(format)
+ HashWithIndifferentAccess.new(content_types)[format]
+ end
+
def content_types
options[:content_types] || CONTENT_TYPES
end
def content_type
- content_types[env['api.format'] || options[:format]] || 'text/html'
+ content_type_for(env['api.format'] || options[:format]) || 'text/html'
end
def mime_types
content_types.invert
end