class Squash::Padrino::Rack
Rack
middleware that catches exceptions thrown outside the scope of Padrino's request processing.
Public Class Methods
new(app)
click to toggle source
Instantiates the middleware.
@param [Array] app The middleware stack.
# File lib/squash/padrino/rack.rb, line 27 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
Rescues any exceptions thrown downstream, notifies Squash
, then re-raises them.
@param [Hash] env The Rack
environment. @return [Hash] The Rack
result to pass up the stack.
# File lib/squash/padrino/rack.rb, line 36 def call(env) begin result = @app.call(env) rescue ::Exception => ex env['squash.notified'] = ::Squash::Ruby.notify(ex, squash_rack_data(env)) raise ex end result end
filter_for_squash(data, kind)
click to toggle source
@abstract
Override this method to implement filtering of sensitive data in the headers, cookies, and rack hashes (see {#squash_rack_data}). The method signature is the same as `Squash::Ruby#filter_for_squash`, but `kind` can also be `:env` for the Rack
environment hash.
# File lib/squash/padrino/rack.rb, line 54 def filter_for_squash(data, kind) data end
squash_rack_data(env)
click to toggle source
@return [Hash<Symbol, Object>] The additional information this
middleware gives to `Squash::Ruby.notify`.
# File lib/squash/padrino/rack.rb, line 60 def squash_rack_data(env) data = { :headers => filter_for_squash(request_headers(env), :headers), :request_method => env['REQUEST_METHOD'].to_s.upcase, :schema => env['rack.url_scheme'], :host => env['SERVER_NAME'], :port => env['SERVER_PORT'], :path => env['PATH_INFO'], :query => env['QUERY_STRING'], :params => filter_for_squash(env['rack.request.query_hash'], :params), :body => filter_for_squash(env['rack.input'].read, :body), :session => filter_for_squash(env['rack.session'], :session), :cookies => filter_for_squash(env['rack.request.cookie_hash'], :cookies), :"rack.env" => filter_for_squash(env, :rack) } env['rack.input'].rewind data end
Private Instance Methods
request_headers(env)
click to toggle source
Extract any rack key/value pairs where the key begins with HTTP_*
# File lib/squash/padrino/rack.rb, line 86 def request_headers(env) env.select { |key, _| key[0, 5] == 'HTTP_' } end