1
# Class representing an HTTP cookie.
3
# In addition to its specific fields and methods, a Cookie instance
4
# is a delegator to the array of its values.
9
# cookie1 = CGI::Cookie::new("name", "value1", "value2", ...)
10
# cookie1 = CGI::Cookie::new("name" => "name", "value" => "value")
11
# cookie1 = CGI::Cookie::new('name' => 'name',
12
# 'value' => ['value1', 'value2', ...],
13
# 'path' => 'path', # optional
14
# 'domain' => 'domain', # optional
15
# 'expires' => Time.now, # optional
16
# 'secure' => true # optional
19
# cgi.out("cookie" => [cookie1, cookie2]) { "string" }
22
# values = cookie1.value
24
# domain = cookie1.domain
25
# expires = cookie1.expires
26
# secure = cookie1.secure
28
# cookie1.name = 'name'
29
# cookie1.value = ['value1', 'value2', ...]
30
# cookie1.path = 'path'
31
# cookie1.domain = 'domain'
32
# cookie1.expires = Time.now + 30
33
# cookie1.secure = true
35
2
@@accept_charset="UTF-8" unless defined?(@@accept_charset)
3
# Class representing an HTTP cookie.
5
# In addition to its specific fields and methods, a Cookie instance
6
# is a delegator to the array of its values.
11
# cookie1 = CGI::Cookie::new("name", "value1", "value2", ...)
12
# cookie1 = CGI::Cookie::new("name" => "name", "value" => "value")
13
# cookie1 = CGI::Cookie::new('name' => 'name',
14
# 'value' => ['value1', 'value2', ...],
15
# 'path' => 'path', # optional
16
# 'domain' => 'domain', # optional
17
# 'expires' => Time.now, # optional
18
# 'secure' => true # optional
21
# cgi.out("cookie" => [cookie1, cookie2]) { "string" }
24
# values = cookie1.value
26
# domain = cookie1.domain
27
# expires = cookie1.expires
28
# secure = cookie1.secure
30
# cookie1.name = 'name'
31
# cookie1.value = ['value1', 'value2', ...]
32
# cookie1.path = 'path'
33
# cookie1.domain = 'domain'
34
# cookie1.expires = Time.now + 30
35
# cookie1.secure = true
36
36
class Cookie < Array
38
38
# Create a new CGI::Cookie object.
40
# The contents of the cookie can be specified as a +name+ and one
41
# or more +value+ arguments. Alternatively, the contents can
42
# be specified as a single hash argument. The possible keywords of
43
# this hash are as follows:
45
# name:: the name of the cookie. Required.
46
# value:: the cookie's value or list of values.
47
# path:: the path for which this cookie applies. Defaults to the
48
# base directory of the CGI script.
49
# domain:: the domain for which this cookie applies.
50
# expires:: the time at which this cookie expires, as a +Time+ object.
51
# secure:: whether this cookie is a secure cookie or not (default to
52
# false). Secure cookies are only transmitted to HTTPS
55
# These keywords correspond to attributes of the cookie object.
41
# Cookie.new(name_string,*value)
42
# Cookie.new(options_hash)
45
# The name of the cookie; in this form, there is no #domain or
46
# #expiration. The #path is gleaned from the +SCRIPT_NAME+ environment
47
# variable, and #secure is false.
49
# value or list of values of the cookie
51
# A Hash of options to initialize this Cookie. Possible options are:
53
# name:: the name of the cookie. Required.
54
# value:: the cookie's value or list of values.
55
# path:: the path for which this cookie applies. Defaults to the
56
# the value of the +SCRIPT_NAME+ environment variable.
57
# domain:: the domain for which this cookie applies.
58
# expires:: the time at which this cookie expires, as a +Time+ object.
59
# secure:: whether this cookie is a secure cookie or not (default to
60
# false). Secure cookies are only transmitted to HTTPS
63
# These keywords correspond to attributes of the cookie object.
56
64
def initialize(name = "", *value)