lib/grape/middleware/base.rb in grape-0.13.0 vs lib/grape/middleware/base.rb in grape-0.14.0
- old
+ new
@@ -1,9 +1,10 @@
module Grape
module Middleware
class Base
attr_reader :app, :env, :options
+ TEXT_HTML = 'text/html'.freeze
# @param [Rack Application] app The standard argument for a Rack middleware.
# @param [Hash] options A hash of options, simply stored for use by subclasses.
def initialize(app, options = {})
@app = app
@@ -48,16 +49,18 @@
def content_types
ContentTypes.content_types_for(options[:content_types])
end
def content_type
- content_type_for(env['api.format'] || options[:format]) || 'text/html'
+ content_type_for(env[Grape::Env::API_FORMAT] || options[:format]) || TEXT_HTML
end
def mime_types
- content_types.each_with_object({}) do |(k, v), types_without_params|
- types_without_params[k] = v.split(';').first
- end.invert
+ types_without_params = {}
+ content_types.each_pair do |k, v|
+ types_without_params[v.split(';').first] = k
+ end
+ types_without_params
end
end
end
end