Class: CookieDomain

Inherits:
Object
  • Object
show all
Defined in:
app/middlewares/cookie_domain.rb

Overview

Instance Method Summary collapse

Constructor Details

#initialize(app, default_domain) ⇒ CookieDomain


3
4
5
6
# File 'app/middlewares/cookie_domain.rb', line 3

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

Instance Method Details

#call(env) ⇒ Object


8
9
10
11
12
# File 'app/middlewares/cookie_domain.rb', line 8

def call(env)
  host = env["HTTP_HOST"].split(':').first
  env["rack.session.options"][:domain] = custom_domain?(host) ? ".#{host}" : "#{@default_domain}"
  @app.call(env)
end

#custom_domain?(host) ⇒ Boolean


14
15
16
17
# File 'app/middlewares/cookie_domain.rb', line 14

def custom_domain?(host)
  domain = @default_domain.sub(/^\./, '')
  host !~ Regexp.new("#{domain}$", Regexp::IGNORECASE)
end