Sha256: 1dc29288a78fb5185189d591ab443be72b255d3928d61493973f59356fc696ff

Contents?: true

Size: 869 Bytes

Versions: 1

Compression:

Stored size: 869 Bytes

Contents

# frozen_string_literal: true
module Rack
  # Rack::BlacklistCookies is a middleware that removes selected cookies from the request and / or response.
  class BlacklistCookies
    def initialize(app)
      @app = app
    end

    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

    def scrub_request?(env)
      !env["HTTP_COOKIE"].nil? && !env["HTTP_COOKIE"].empty? && BlacklistCookies.request_blacklist(env)
    end

    def scrub_response?(env, headers)
      !headers["Set-Cookie"].nil? && !headers["Set-Cookie"].empty? && BlacklistCookies.response_blacklist(env)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-blacklist_cookies-1.0.0 lib/rack/blacklist_cookies.rb