class Sparrow::Middleware
Parent middleware class for both Requests and Responses. Provides common accessors, but does not modify the http message.
Attributes
@return [Object] the parent Rack application in the stack.
@return [Array<String>] the rack body after the middleware call
@return [Hash<String, String>] the HTTP Headers after the middleware call
@return [Array<Integer>] List of ignored HTTP response codes @see Configuration#ignored_response_codes
@return [Integer] the HTTP status after the middleware call
Public Class Methods
Creates a new Middleware
object @param [#call] app the Rack application as defined by. Any object that
responds to #call as defined in {https://rack.github.io/}.
# File lib/sparrow/middleware.rb, line 23 def initialize(app) @app = app @ignored_response_codes = ignored_response_codes end
Public Instance Methods
@return [Array] The Rack tuple of status, headers and body as defined by {rack.github.io/} Does nothing by default.
# File lib/sparrow/middleware.rb, line 31 def call(env) @last_env = env @status, @headers, @body = @app.call(convert(env)) end
Converts the Rack environment Does nothing. @param [Hash] env the rack env @return [Hash] the rack env
# File lib/sparrow/middleware.rb, line 40 def convert(env) env end
Private Instance Methods
# File lib/sparrow/middleware.rb, line 65 def last_env @last_env || {} end
# File lib/sparrow/middleware.rb, line 46 def steward Steward.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
# File lib/sparrow/middleware.rb, line 54 def strategy strategy = if steward.has_processable_http_message? Strategies::RawInput else Strategies::Ignore end Sparrow.logger.debug("#{self.class.name} choosing strategy #{strategy.name}") strategy end