class Rack::UtmCookies
Constants
- VERSION
Public Class Methods
new(app, options = {})
click to toggle source
# File lib/rack/utm_cookies.rb, line 5 def initialize(app, options = {}) @app = app @domain = options[:domain] || nil @ttl = options[:ttl] || 60*60*24*30 # 30 days end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack/utm_cookies.rb, line 11 def call(env) req = Rack::Request.new(env) # tack them on so they're available down # the middleware stack for this current request env['HTTP_COOKIE'] = '' unless env['HTTP_COOKIE'] utm_cookies_to_set(req).each do |name, value| env['HTTP_COOKIE'] += "; #{name}=#{value}" end # pass the call down the middleware stack status, headers, body = @app.call(env) # make sure the proper set-cookie response headers # are set so we have the cookies for future requests. utm_cookies_to_set(req).each do |name, value| cookie_hash = { :value => value, :expires => Time.now + @ttl, :path => '/', } cookie_hash[:domain] = @domain if @domain Rack::Utils.set_cookie_header!(headers, name, cookie_hash) end [status, headers, body] end