class Grape::Middleware::Base
def after; end
-
(Response, nil)
- a Rack SPEC response or nil to call the application afterwards.
Other tags:
- Abstract: -
def after; end
def before; end
- Abstract: -
def before; end
def call(env)
def call(env) dup.call!(env).to_a end
def call!(env)
def call!(env) @env = env before begin @app_response = @app.call(@env) ensure begin after_response = after rescue StandardError => e warn "caught error of type #{e.class} in after callback inside #{self.class.name} : #{e.message}" raise e end end response = after_response || @app_response merge_headers response response end
def content_type
def content_type content_type_for(env[Grape::Env::API_FORMAT] || options[:format]) || TEXT_HTML end
def content_type_for(format)
def content_type_for(format) content_types_indifferent_access[format] end
def content_types
def content_types @content_types ||= Grape::ContentTypes.content_types_for(options[:content_types]) end
def content_types_indifferent_access
def content_types_indifferent_access @content_types_indifferent_access ||= content_types.with_indifferent_access end
def default_options
def default_options {} end
def initialize(app, *options)
-
options
(Hash
) -- A hash of options, simply stored for use by subclasses. -
app
(Rack Application
) -- The standard argument for a Rack middleware.
def initialize(app, *options) @app = app @options = options.any? ? default_options.deep_merge(options.shift) : default_options @app_response = nil end
def merge_headers(response)
def merge_headers(response) return unless headers.is_a?(Hash) case response when Rack::Response then response.headers.merge!(headers) when Array then response[1].merge!(headers) end end
def mime_types
def mime_types @mime_types ||= Grape::ContentTypes.mime_types_for(content_types) end
def response
def response return @app_response if @app_response.is_a?(Rack::Response) @app_response = Rack::Response.new(@app_response[2], @app_response[0], @app_response[1]) end