Class: Rack::UtmCookies
- Inherits:
-
Object
- Object
- Rack::UtmCookies
- Defined in:
- lib/rack/utm_cookies.rb,
lib/rack/utm_cookies/version.rb
Constant Summary collapse
- VERSION =
"0.1.1"
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = {}) ⇒ UtmCookies
constructor
A new instance of UtmCookies.
Constructor Details
#initialize(app, options = {}) ⇒ UtmCookies
Returns a new instance of UtmCookies.
5 6 7 8 9 |
# File 'lib/rack/utm_cookies.rb', line 5 def initialize(app, = {}) @app = app @domain = [:domain] || nil @ttl = [:ttl] || 60*60*24*30 # 30 days end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# 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'] (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. (req).each do |name, value| = { :value => value, :expires => Time.now + @ttl, :path => '/', } [:domain] = @domain if @domain Rack::Utils.(headers, name, ) end [status, headers, body] end |