Class: Rack::BlacklistCookies

Inherits:
Object
  • Object
show all
Defined in:
lib/rack-blacklist_cookies.rb,
lib/rack/blacklist_cookies.rb,
lib/rack/blacklist_cookies/version.rb,
lib/rack/blacklist_cookies/scrubber.rb,
lib/rack/blacklist_cookies/configuration.rb

Overview

Rack::BlacklistCookies is a middleware that removes selected cookies from the request and / or response.

Defined Under Namespace

Classes: BaseScrubber, Configuration, ConfigurationError, RequestScrubber, ResponseScrubber

Constant Summary collapse

VERSION =
"1.0.0".freeze

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ BlacklistCookies

Returns a new instance of BlacklistCookies.



5
6
7
# File 'lib/rack/blacklist_cookies.rb', line 5

def initialize(app)
  @app = app
end

Class Method Details

.configurationObject



10
11
12
# File 'lib/rack-blacklist_cookies.rb', line 10

def self.configuration
  @configuration ||= Configuration.new
end

.configureObject



14
15
16
17
18
19
20
# File 'lib/rack-blacklist_cookies.rb', line 14

def self.configure
  yield(configuration)
  configuration.validate
rescue ConfigurationError => error
  configuration.reset
  raise error
end

.request_blacklist(env) ⇒ Object



22
23
24
# File 'lib/rack-blacklist_cookies.rb', line 22

def self.request_blacklist(env)
  configuration.request_blacklist[env["PATH_INFO"]]
end

.response_blacklist(env) ⇒ Object



26
27
28
# File 'lib/rack-blacklist_cookies.rb', line 26

def self.response_blacklist(env)
  configuration.response_blacklist[env["PATH_INFO"]]
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/rack/blacklist_cookies.rb', line 9

def call(env)
  env["HTTP_COOKIE"] = "#{RequestScrubber.new(env, env["HTTP_COOKIE"])}" if scrub_request?(env)

  status, headers, body = @app.call(env)

  headers["Set-Cookie"] = "#{ResponseScrubber.new(env, headers["Set-Cookie"])}" if scrub_response?(env, headers)

  [status, headers, body]
end