Class: HttpLog::Middleware
- Inherits:
-
Object
- Object
- HttpLog::Middleware
- Defined in:
- lib/http_log/middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Middleware
constructor
A new instance of Middleware.
- #passes_filters? ⇒ Boolean
Constructor Details
#initialize(app) ⇒ Middleware
Returns a new instance of Middleware.
3 4 5 |
# File 'lib/http_log/middleware.rb', line 3 def initialize(app) @app = app end |
Instance Method Details
#call(env) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/http_log/middleware.rb', line 7 def call(env) @proxy = HttpRequest.new(env) if passes_filters? request = HttpLog::Request.from_request(@proxy) HttpLog.callbacks.each do |callback| callback.call @proxy, request end request.save env['http_log.request_id'] = request.id.to_s end @app.call env end |
#passes_filters? ⇒ Boolean
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/http_log/middleware.rb', line 23 def passes_filters? HttpLog.filters.each do |filter| matches_filter = if filter.is_a? Symbol @proxy.path_info =~ /\.#{filter}$/ elsif filter.is_a? Regexp @proxy.url =~ filter else filter.call @proxy end return false if matches_filter end true end |