Class: Lotus::Action::CookieJar
- Inherits:
-
Object
- Object
- Lotus::Action::CookieJar
- Defined in:
- lib/lotus/action/cookie_jar.rb
Overview
A set of HTTP Cookies
It acts as an Hash
Constant Summary collapse
- HTTP_HEADER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The key that returns raw cookies from the Rack env
'HTTP_COOKIE'.freeze
- RACK_SESSION_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The key used by Rack to set the session cookie
We let CookieJar to NOT take care of this cookie, but it leaves the responsibility to the Rack middleware that handle sessions.
This prevents
Set-Cookie
to be sent twice. :'rack.session'
- COOKIE_HASH_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The key used by Rack to set the cookies as an Hash in the env
'rack.request.cookie_hash'.freeze
- COOKIE_STRING_KEY =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
The key used by Rack to set the cookies as a String in the env
'rack.request.cookie_string'.freeze
- COOKIE_SEPARATOR =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
';,'.freeze
Instance Method Summary collapse
-
#[](key) ⇒ Object?
Returns the object associated with the given key.
-
#[]=(key, value) ⇒ void
Associate the given value with the given key and store them.
-
#finish ⇒ void
Finalize itself, by setting the proper headers to add and remove cookies, before the response is returned to the webserver.
-
#initialize(env, headers, default_options) ⇒ CookieJar
constructor
Initialize the CookieJar.
Constructor Details
#initialize(env, headers, default_options) ⇒ CookieJar
Initialize the CookieJar
56 57 58 59 60 |
# File 'lib/lotus/action/cookie_jar.rb', line 56 def initialize(env, headers, ) @_headers = headers @cookies = Utils::Hash.new(extract(env)).symbolize! @default_options = end |
Instance Method Details
#[](key) ⇒ Object?
Returns the object associated with the given key
82 83 84 |
# File 'lib/lotus/action/cookie_jar.rb', line 82 def [](key) @cookies[key] end |
#[]=(key, value) ⇒ void
This method returns an undefined value.
Associate the given value with the given key and store them
105 106 107 |
# File 'lib/lotus/action/cookie_jar.rb', line 105 def []=(key, value) @cookies[key] = value end |
#finish ⇒ void
This method returns an undefined value.
Finalize itself, by setting the proper headers to add and remove cookies, before the response is returned to the webserver.
70 71 72 73 |
# File 'lib/lotus/action/cookie_jar.rb', line 70 def finish @cookies.delete(RACK_SESSION_KEY) @cookies.each { |k,v| v.nil? ? (k) : (k, _merge_default_values(v)) } end |