summaryrefslogtreecommitdiff
path: root/lib/webrick/cookie.rb
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-26 01:12:54 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-26 01:12:54 +0000
commit28afe277a8e543da0e6353bdacbcad0b69739e06 (patch)
tree1591c370f08ab4db6c888eea99f2936262e137ca /lib/webrick/cookie.rb
parent89232d1dd97251b6fc626d4338c49e9e8c4f6535 (diff)
* lib/webrick/accesslog.rb: Improved WEBrick documentation.
* lib/webrick/cgi.rb: ditto. * lib/webrick/config.rb: ditto. * lib/webrick/cookie.rb: ditto. * lib/webrick/httpauth/authenticator.rb: ditto. * lib/webrick/httpauth/basicauth.rb: ditto. * lib/webrick/httpauth/digestauth.rb: ditto. * lib/webrick/httpproxy.rb: ditto. * lib/webrick/httprequest.rb: ditto. * lib/webrick/httpresponse.rb: ditto. * lib/webrick/https.rb: ditto. * lib/webrick/httpserver.rb: ditto. * lib/webrick/httpservlet/cgihandler.rb: ditto. * lib/webrick/httpservlet/filehandler.rb: ditto. * lib/webrick/httpservlet/prochandler.rb: ditto. * lib/webrick/httputils.rb: ditto. * lib/webrick/httpversion.rb: ditto. * lib/webrick/log.rb: ditto. * lib/webrick/server.rb: ditto. * lib/webrick/ssl.rb: ditto. * lib/webrick/utils.rb: ditto. * lib/webrick/version.rb: ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38945 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/webrick/cookie.rb')
-rw-r--r--lib/webrick/cookie.rb71
1 files changed, 66 insertions, 5 deletions
diff --git a/lib/webrick/cookie.rb b/lib/webrick/cookie.rb
index 814e6645a3..3cf8928bb0 100644
--- a/lib/webrick/cookie.rb
+++ b/lib/webrick/cookie.rb
@@ -12,14 +12,56 @@ require 'time'
require 'webrick/httputils'
module WEBrick
+
+ ##
+ # Processes HTTP cookies
+
class Cookie
+ ##
+ # The cookie name
+
attr_reader :name
- attr_accessor :value, :version
- attr_accessor :domain, :path, :secure
- attr_accessor :comment, :max_age
+
+ ##
+ # The cookie value
+
+ attr_accessor :value
+
+ ##
+ # The cookie version
+
+ attr_accessor :version
+
+ ##
+ # The cookie domain
+ attr_accessor :domain
+
+ ##
+ # The cookie path
+
+ attr_accessor :path
+
+ ##
+ # Is this a secure cookie?
+
+ attr_accessor :secure
+
+ ##
+ # The cookie comment
+
+ attr_accessor :comment
+
+ ##
+ # The maximum age of the cookie
+
+ attr_accessor :max_age
+
#attr_accessor :comment_url, :discard, :port
+ ##
+ # Creates a new cookie with the given +name+ and +value+
+
def initialize(name, value)
@name = name
@value = value
@@ -29,14 +71,25 @@ module WEBrick
@expires = @comment_url = @discard = @port = nil
end
+ ##
+ # 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.
+
def expires=(t)
@expires = t && (t.is_a?(Time) ? t.httpdate : t.to_s)
end
+ ##
+ # Retrieves the expiration time as a Time
+
def expires
@expires && Time.parse(@expires)
end
+ ##
+ # The cookie string suitable for use in an HTTP header
+
def to_s
ret = ""
ret << @name << "=" << @value
@@ -50,8 +103,10 @@ module WEBrick
ret
end
- # Cookie::parse()
- # It parses Cookie field sent from the user agent.
+ ##
+ # Parses a Cookie field sent from the user-agent. Returns an array of
+ # cookies.
+
def self.parse(str)
if str
ret = []
@@ -76,6 +131,9 @@ module WEBrick
end
end
+ ##
+ # Parses the cookie in +str+
+
def self.parse_set_cookie(str)
cookie_elem = str.split(/;/)
first_elem = cookie_elem.shift
@@ -101,6 +159,9 @@ module WEBrick
return cookie
end
+ ##
+ # Parses the cookies in +str+
+
def self.parse_set_cookies(str)
return str.split(/,(?=[^;,]*=)|,$/).collect{|c|
parse_set_cookie(c)