class Rack::BlacklistCookies
Rack::BlacklistCookies
holds onto configuration values at the class level
Rack::BlacklistCookies
is a middleware that removes selected cookies from the request and / or response.
Constants
- VERSION
Public Class Methods
configuration()
click to toggle source
# File lib/rack-blacklist_cookies.rb, line 10 def self.configuration @configuration ||= Configuration.new end
configure() { |configuration| ... }
click to toggle source
# File lib/rack-blacklist_cookies.rb, line 14 def self.configure yield(configuration) configuration.validate rescue ConfigurationError => error configuration.reset raise error end
new(app)
click to toggle source
# File lib/rack/blacklist_cookies.rb, line 5 def initialize(app) @app = app end
request_blacklist(env)
click to toggle source
# File lib/rack-blacklist_cookies.rb, line 22 def self.request_blacklist(env) configuration.request_blacklist[env["PATH_INFO"]] end
response_blacklist(env)
click to toggle source
# File lib/rack-blacklist_cookies.rb, line 26 def self.response_blacklist(env) configuration.response_blacklist[env["PATH_INFO"]] end
Public Instance Methods
call(env)
click to toggle source
# 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
Private Instance Methods
scrub_request?(env)
click to toggle source
# File lib/rack/blacklist_cookies.rb, line 21 def scrub_request?(env) !env["HTTP_COOKIE"].nil? && !env["HTTP_COOKIE"].empty? && BlacklistCookies.request_blacklist(env) end
scrub_response?(env, headers)
click to toggle source
# File lib/rack/blacklist_cookies.rb, line 25 def scrub_response?(env, headers) !headers["Set-Cookie"].nil? && !headers["Set-Cookie"].empty? && BlacklistCookies.response_blacklist(env) end