Class: Rack::CookieRewrite

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

Overview

Rack middleware to add an alternate header for Cookies.

Instance Method Summary collapse

Constructor Details

#initialize(app, prefix) ⇒ CookieRewrite

Returns a new instance of CookieRewrite.



6
7
8
9
# File 'lib/rack/cookie_rewrite.rb', line 6

def initialize(app, prefix)
  @app = app
  @prefix = prefix
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# 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