Sha256: 6f7935392610ce07733a6dbc021753b62ac9eaa4c9fb7f55325e00c0950755c0
Contents?: true
Size: 1.55 KB
Versions: 1
Compression:
Stored size: 1.55 KB
Contents
module Sparrow ## # Handles the Response conversion class ResponseMiddleware < Middleware ## # This call ends the rack chain # @param [Hash] env the Rack environment # @return [Array<String, Hash, Array<String>>] the Rack return Array def call(env) @last_env = env @status, @headers, @body = app.call(env) [status, headers, converted_response_body] end private def steward ResponseSteward.new(http_message, allowed_content_types: Sparrow.configuration.allowed_content_types, allowed_accepts: Sparrow.configuration.allowed_accepts, excluded_routes: Sparrow.configuration.excluded_routes, ignored_response_codes: Sparrow.configuration.ignored_response_codes) end def converted_response_body # return the original body if we are not going to process it return body unless steward.has_processable_http_message? response_body = Sparrow::Strategies::JsonFormatStrategy.convert(body) return [] if response_body.blank? @headers.delete 'Content-Length' response_strategy = strategy.new(last_env, :response, response_body) response_strategy.handle Array(response_strategy.json_body) end def http_message response_message = ResponseHttpMessage.new(last_env) response_message.status = status response_message.body = body response_message.headers = headers response_message end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
cp-sparrow-0.0.14 | lib/sparrow/response_middleware.rb |