Class: Grape::Middleware::Formatter

Inherits:
Base
  • Object
show all
Defined in:
lib/grape/middleware/formatter.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{
  default_format: :txt
}.freeze

Instance Attribute Summary

Attributes inherited from Base

#app, #env, #options

Instance Method Summary collapse

Methods inherited from Base

#call, #call!, #content_type, #content_type_for, #content_types, #context, #initialize, #mime_types, #query_params, #rack_request, #response

Methods included from DSL::Headers

#header

Constructor Details

This class inherits a constructor from Grape::Middleware::Base

Instance Method Details

#afterObject



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/grape/middleware/formatter.rb', line 15

def after
  return unless @app_response

  status, headers, bodies = *@app_response

  if Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include?(status)
    [status, headers, []]
  else
    build_formatted_response(status, headers, bodies)
  end
end

#beforeObject



10
11
12
13
# File 'lib/grape/middleware/formatter.rb', line 10

def before
  negotiate_content_type
  read_body_input
end