Class: Rack::MergeCookies

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/merge-cookies.rb,
lib/rack/merge-cookies/version.rb

Constant Summary collapse

VERSION =
'0.0.1'

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ MergeCookies

Returns a new instance of MergeCookies.



3
4
5
# File 'lib/rack/merge-cookies.rb', line 3

def initialize(app, options = {})
  @app, @header_name = app, options[:header_name]
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
# File 'lib/rack/merge-cookies.rb', line 11

def call(env)
  custom_cookie = env[custom_cookie_name]
  unless custom_cookie.nil?
    cookie = (env['HTTP_COOKIE'] || '').gsub(/;$/, '')
    env['HTTP_COOKIE'] = cookie + '; ' + custom_cookie
  end
  @app.call(env)
end


7
8
9
# File 'lib/rack/merge-cookies.rb', line 7

def custom_cookie_name
  'HTTP_' + @header_name.upcase.gsub('-', '_')
end