Processes HTTP cookies
Methods
- E
- N
- P
- T
Attributes
[RW] | comment | The cookie comment |
[RW] | domain | The cookie domain |
[RW] | max_age | The maximum age of the cookie |
[R] | name | The cookie name |
[RW] | path | The cookie path |
[RW] | secure | Is this a secure cookie? |
[RW] | value | The cookie value |
[RW] | version | The cookie version |
Class Public methods
new(name, value)
Link
Creates a new cookie with the given name
and
value
parse(str)
Link
Parses a Cookie field sent from the user-agent. Returns an array of cookies.
# File lib/webrick/cookie.rb, line 110 def self.parse(str) if str ret = [] cookie = nil ver = 0 str.split(/[;,]\s+/).each{|x| key, val = x.split(/=/,2) val = val ? HTTPUtils::dequote(val) : "" case key when "$Version"; ver = val.to_i when "$Path"; cookie.path = val when "$Domain"; cookie.domain = val when "$Port"; cookie.port = val else ret << cookie if cookie cookie = self.new(key, val) cookie.version = ver end } ret << cookie if cookie ret end end
Instance Public methods
expires=(t)
Link
Sets the cookie expiration to the time t
. The expiration time
may be a false value to disable expiration or a Time or HTTP format time string to set the
expiration date.
to_s()
Link
The cookie string suitable for use in an HTTP header
# File lib/webrick/cookie.rb, line 93 def to_s ret = "" ret << @name << "=" << @value ret << "; " << "Version=" << @version.to_s if @version > 0 ret << "; " << "Domain=" << @domain if @domain ret << "; " << "Expires=" << @expires if @expires ret << "; " << "Max-Age=" << @max_age.to_s if @max_age ret << "; " << "Comment=" << @comment if @comment ret << "; " << "Path=" << @path if @path ret << "; " << "Secure" if @secure ret end