Class: Rack::CookieLogger::Middleware

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/cookie_logger/middleware.rb

Overview

Logs:

  • request cookies (the ‘Cookie:` header)

  • response cookies (the ‘Set-Cookie:` header)

Constant Summary collapse

LOG_PREFIX =
'CookieLogger: '
[
  'session',
  'credentials',
  'password',
  'token'
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



20
21
22
# File 'lib/rack/cookie_logger/middleware.rb', line 20

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/rack/cookie_logger/middleware.rb', line 24

def call(env)
  @logger = env[::Rack::RACK_ERRORS]
  log_request_cookies(::Rack::Request.new(env))
  status, headers, body = @app.call(env)
  log_response_cookies(::Rack::Response.new([], status, headers))
  [status, headers, body]
end