Class: IWonder::Logging::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/i_wonder/logging/middleware.rb

Constant Summary collapse

NO_USER_KEY =
"_no_user"
LAST_HIT_TIME =
"_last_hit"
BOT_REGEX =
/msnbot|yahoo|slurp|googlebot/

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



8
9
10
# File 'lib/i_wonder/logging/middleware.rb', line 8

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/i_wonder/logging/middleware.rb', line 12

def call(env)
  env[ENV_KEY] = {}
  @status, @headers, @response = @app.call(env)
  
  if should_log_anything?(env)
    
    unless env['User-Agent'] =~ BOT_REGEX
      env["rack.session"] ||= {}
      process_env(env)
    end
  end

  [@status, @headers, @response]
end