lib/grape/middleware/formatter.rb in grape-1.2.5 vs lib/grape/middleware/formatter.rb in grape-1.3.0
- old
+ new
@@ -1,11 +1,13 @@
+# frozen_string_literal: true
+
require 'grape/middleware/base'
module Grape
module Middleware
class Formatter < Base
- CHUNKED = 'chunked'.freeze
+ CHUNKED = 'chunked'
def default_options
{
default_format: :txt,
formatters: {},
@@ -50,11 +52,11 @@
throw :error, status: 500, message: e.message, backtrace: e.backtrace, original_exception: e
end
def fetch_formatter(headers, options)
api_format = mime_types[headers[Grape::Http::Headers::CONTENT_TYPE]] || env[Grape::Env::API_FORMAT]
- Grape::Formatter.formatter_for(api_format, options)
+ Grape::Formatter.formatter_for(api_format, **options)
end
# Set the content type header for the API format if it is not already present.
#
# @param headers [Hash]
@@ -95,10 +97,10 @@
fmt = request.media_type ? mime_types[request.media_type] : options[:default_format]
unless content_type_for(fmt)
throw :error, status: 415, message: "The provided content-type '#{request.media_type}' is not supported."
end
- parser = Grape::Parser.parser_for fmt, options
+ parser = Grape::Parser.parser_for fmt, **options
if parser
begin
body = (env[Grape::Env::API_REQUEST_BODY] = parser.call(body, env))
if body.is_a?(Hash)
env[Grape::Env::RACK_REQUEST_FORM_HASH] = if env[Grape::Env::RACK_REQUEST_FORM_HASH]