class Sparrow::Middleware

Parent middleware class for both Requests and Responses. Provides common accessors, but does not modify the http message.

Attributes

app[R]

@return [Object] the parent Rack application in the stack.

body[R]

@return [Array<String>] the rack body after the middleware call

headers[R]

@return [Hash<String, String>] the HTTP Headers after the middleware call

ignored_response_codes[R]

@return [Array<Integer>] List of ignored HTTP response codes @see Configuration#ignored_response_codes

status[R]

@return [Integer] the HTTP status after the middleware call

Public Class Methods

new(app) click to toggle source

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

call(env) click to toggle source

@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
convert(env) click to toggle source

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

last_env() click to toggle source
# File lib/sparrow/middleware.rb, line 65
def last_env
  @last_env || {}
end
steward() click to toggle source
# 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
strategy() click to toggle source
# 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