class Rack::CookieRewrite

Rack middleware to add an alternate header for Cookies.

Public Class Methods

new(app, prefix) click to toggle source
# File lib/rack/cookie_rewrite.rb, line 6
def initialize(app, prefix)
  @app = app
  @prefix = prefix
end

Public Instance Methods

call(env) click to toggle source
# File lib/rack/cookie_rewrite.rb, line 11
def call(env)
  (cookie = env["HTTP_X_#{@prefix}_COOKIE"]) &&
    (env['HTTP_COOKIE'] = cookie)

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

  (cookie = headers['Set-Cookie']) &&
    headers["X-#{@prefix}-Set-Cookie"] = cookie

  [status, headers, body]
end