Parent

Included Modules

Files

WebAgent::Cookie

Constants

USE
SECURE
DOMAIN
PATH
DISCARD
OVERRIDE
OVERRIDE_OK

Attributes

name[RW]
value[RW]
domain[RW]
path[RW]
expires[RW]
url[RW]
use[W]
secure[W]
discard[W]
domain_orig[W]
path_orig[W]
override[W]

Public Class Methods

new() click to toggle source
    # File lib/httpclient/cookie.rb, line 73
73:     def initialize()
74:       @name = @value = @domain = @path = nil
75:       @expires = nil
76:       @url = nil
77:       @use = @secure = @discard = @domain_orig = @path_orig = @override = nil
78:     end

Public Instance Methods

discard?() click to toggle source
    # File lib/httpclient/cookie.rb, line 80
80:     def discard?
81:       @discard
82:     end
domain_orig?() click to toggle source
    # File lib/httpclient/cookie.rb, line 92
92:     def domain_orig?
93:       @domain_orig
94:     end
flag() click to toggle source
     # File lib/httpclient/cookie.rb, line 104
104:     def flag
105:       flg = 0
106:       flg += USE  if @use
107:       flg += SECURE  if @secure
108:       flg += DOMAIN  if @domain_orig
109:       flg += PATH  if @path_orig
110:       flg += DISCARD if @discard
111:       flg += OVERRIDE if @override
112:       flg
113:     end
join_quotedstr(array, sep) click to toggle source
     # File lib/httpclient/cookie.rb, line 137
137:     def join_quotedstr(array, sep)
138:       ret = Array.new()
139:       old_elem = nil
140:       array.each{|elem|
141:         if (elem.scan(/"/).length % 2) == 0
142:           if old_elem
143:             old_elem << sep << elem
144:           else
145:             ret << elem
146:             old_elem = nil
147:           end  
148:         else
149:           if old_elem
150:             old_elem << sep << elem
151:             ret << old_elem
152:             old_elem = nil
153:           else
154:             old_elem = elem.dup
155:           end
156:         end
157:       }
158:       ret
159:     end
match?(url) click to toggle source
     # File lib/httpclient/cookie.rb, line 125
125:     def match?(url)
126:       domainname = url.host
127:       if (!domainname ||
128:           !domain_match(domainname, @domain) ||
129:           (@path && !head_match?(@path, url.path)) ||
130:           (@secure && (url.scheme != 'https')) )
131:         return false
132:       else
133:         return true
134:       end
135:     end
override?() click to toggle source
     # File lib/httpclient/cookie.rb, line 100
100:     def override?
101:       @override
102:     end
parse(str, url) click to toggle source
     # File lib/httpclient/cookie.rb, line 161
161:     def parse(str, url)
162:       @url = url
163:       # TODO: should not depend on join_quotedstr. scan with escape like CSV.
164:       cookie_elem = str.split(/;/)
165:       cookie_elem = join_quotedstr(cookie_elem, ';')
166:       cookie_elem -= [""] # del empty elements, a cookie might included ";;"
167:       first_elem = cookie_elem.shift
168:       if first_elem !~ /([^=]*)(\=(.*))?/
169:         return
170:         ## raise ArgumentError 'invalid cookie value'
171:       end
172:       @name = $1.strip
173:       @value = normalize_cookie_value($3)
174:       cookie_elem.each{|pair|
175:         key, value = pair.split(/=/, 2)  ## value may nil
176:         key.strip!
177:         value = normalize_cookie_value(value)
178:         case key.downcase
179:         when 'domain'
180:           @domain = value
181:         when 'expires'
182:           @expires = nil
183:           begin
184:             @expires = Time.parse(value).gmtime() if value
185:           rescue ArgumentError
186:           end
187:         when 'path'
188:           @path = value
189:         when 'secure'
190:           @secure = true  ## value may nil, but must 'true'.
191:         else
192:           ## ignore
193:         end
194:       }
195:     end
path_orig?() click to toggle source
    # File lib/httpclient/cookie.rb, line 96
96:     def path_orig?
97:       @path_orig
98:     end
secure?() click to toggle source
    # File lib/httpclient/cookie.rb, line 88
88:     def secure?
89:       @secure
90:     end
set_flag(flag) click to toggle source
     # File lib/httpclient/cookie.rb, line 115
115:     def set_flag(flag)
116:       flag = flag.to_i
117:       @use = true      if flag & USE > 0
118:       @secure = true   if flag & SECURE > 0
119:       @domain_orig = true if flag & DOMAIN > 0
120:       @path_orig = true if flag & PATH > 0
121:       @discard  = true if flag & DISCARD > 0
122:       @override = true if flag & OVERRIDE > 0
123:     end
use?() click to toggle source
    # File lib/httpclient/cookie.rb, line 84
84:     def use?
85:       @use
86:     end

Private Instance Methods

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.