Class: Rack::CommonCookies

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

Overview

Rack middleware to use common cookies across domain and subdomains.

Constant Summary collapse

DOMAIN_REGEXP =
/([^.]*)\.([^.]*|..\...|...\...|..\....)$/
LOCALHOST_OR_IP_REGEXP =
/^([\d.]+|localhost)$/
PORT =
/:\d+$/

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ CommonCookies

Returns a new instance of CommonCookies.



13
14
15
# File 'lib/rack/contrib/common_cookies.rb', line 13

def initialize(app)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/rack/contrib/common_cookies.rb', line 17

def call(env)
  status, headers, body = @app.call(env)
  headers = HEADERS_KLASS.new.merge(headers)

  host = env['HTTP_HOST'].sub PORT, ''
  share_cookie(headers, host)

  [status, headers, body]
end