httpclient 2.1.5 → 2.8.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/README.md +85 -0
- data/bin/httpclient +77 -0
- data/bin/jsonclient +85 -0
- data/lib/hexdump.rb +50 -0
- data/lib/http-access2.rb +6 -4
- data/lib/httpclient/auth.rb +575 -173
- data/lib/httpclient/cacert.pem +3952 -0
- data/lib/httpclient/cacert1024.pem +3866 -0
- data/lib/httpclient/connection.rb +6 -2
- data/lib/httpclient/cookie.rb +162 -504
- data/lib/httpclient/http.rb +334 -119
- data/lib/httpclient/include_client.rb +85 -0
- data/lib/httpclient/jruby_ssl_socket.rb +588 -0
- data/lib/httpclient/session.rb +385 -288
- data/lib/httpclient/ssl_config.rb +195 -155
- data/lib/httpclient/ssl_socket.rb +150 -0
- data/lib/httpclient/timeout.rb +14 -10
- data/lib/httpclient/util.rb +142 -6
- data/lib/httpclient/version.rb +3 -0
- data/lib/httpclient/webagent-cookie.rb +459 -0
- data/lib/httpclient.rb +509 -202
- data/lib/jsonclient.rb +63 -0
- data/lib/oauthclient.rb +111 -0
- data/sample/async.rb +8 -0
- data/sample/auth.rb +11 -0
- data/sample/cookie.rb +18 -0
- data/sample/dav.rb +103 -0
- data/sample/howto.rb +49 -0
- data/sample/jsonclient.rb +67 -0
- data/sample/oauth_buzz.rb +57 -0
- data/sample/oauth_friendfeed.rb +59 -0
- data/sample/oauth_twitter.rb +61 -0
- data/sample/ssl/0cert.pem +22 -0
- data/sample/ssl/0key.pem +30 -0
- data/sample/ssl/1000cert.pem +19 -0
- data/sample/ssl/1000key.pem +18 -0
- data/sample/ssl/htdocs/index.html +10 -0
- data/sample/ssl/ssl_client.rb +22 -0
- data/sample/ssl/webrick_httpsd.rb +29 -0
- data/sample/stream.rb +21 -0
- data/sample/thread.rb +27 -0
- data/sample/wcat.rb +21 -0
- data/test/ca-chain.pem +44 -0
- data/test/ca.cert +23 -0
- data/test/client-pass.key +18 -0
- data/test/client.cert +19 -0
- data/test/client.key +15 -0
- data/test/helper.rb +131 -0
- data/test/htdigest +1 -0
- data/test/htpasswd +2 -0
- data/test/jruby_ssl_socket/test_pemutils.rb +32 -0
- data/test/runner.rb +2 -0
- data/test/server.cert +19 -0
- data/test/server.key +15 -0
- data/test/sslsvr.rb +65 -0
- data/test/subca.cert +21 -0
- data/test/test_auth.rb +492 -0
- data/test/test_cookie.rb +309 -0
- data/test/test_hexdump.rb +14 -0
- data/test/test_http-access2.rb +508 -0
- data/test/test_httpclient.rb +2145 -0
- data/test/test_include_client.rb +52 -0
- data/test/test_jsonclient.rb +80 -0
- data/test/test_ssl.rb +559 -0
- data/test/test_webagent-cookie.rb +465 -0
- metadata +85 -44
- data/lib/httpclient/auth.rb.orig +0 -513
- data/lib/httpclient/cacert.p7s +0 -1579
- data/lib/httpclient.rb.orig +0 -1020
- data/lib/tags +0 -908
data/lib/httpclient/cookie.rb
CHANGED
@@ -1,562 +1,220 @@
|
|
1
|
-
#
|
2
|
-
|
3
|
-
#
|
4
|
-
# http://www.rubycolor.org/arc/.
|
1
|
+
# do not override if httpclient/webagent-cookie is loaded already
|
2
|
+
unless defined?(HTTPClient::CookieManager)
|
3
|
+
begin # for catching LoadError and load webagent-cookie instead
|
5
4
|
|
5
|
+
require 'http-cookie'
|
6
|
+
require 'httpclient/util'
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
# are quoted from it. I'm thanksful for author(s) of it.
|
11
|
-
#
|
12
|
-
# w3m homepage: http://ei5nazha.yz.yamagata-u.ac.jp/~aito/w3m/eng/
|
13
|
-
|
14
|
-
require 'uri'
|
15
|
-
require 'time'
|
16
|
-
require 'monitor'
|
17
|
-
|
18
|
-
class WebAgent
|
19
|
-
|
20
|
-
module CookieUtils
|
8
|
+
class HTTPClient
|
9
|
+
class CookieManager
|
10
|
+
include HTTPClient::Util
|
21
11
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
12
|
+
attr_reader :format, :jar
|
13
|
+
attr_accessor :cookies_file
|
25
14
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
15
|
+
def initialize(cookies_file = nil, format = WebAgentSaver, jar = HTTP::CookieJar.new)
|
16
|
+
@cookies_file = cookies_file
|
17
|
+
@format = format
|
18
|
+
@jar = jar
|
19
|
+
load_cookies if @cookies_file
|
20
|
+
end
|
21
|
+
|
22
|
+
def load_cookies
|
23
|
+
check_cookies_file
|
24
|
+
@jar.clear
|
25
|
+
@jar.load(@cookies_file, :format => @format)
|
26
|
+
end
|
27
|
+
|
28
|
+
def save_cookies(session = false)
|
29
|
+
check_cookies_file
|
30
|
+
@jar.save(@cookies_file, :format => @format, :session => session)
|
31
|
+
end
|
32
|
+
|
33
|
+
def cookies(uri = nil)
|
34
|
+
cookies = @jar.cookies(uri)
|
35
|
+
# TODO: return HTTP::Cookie in the future
|
36
|
+
cookies.map { |cookie|
|
37
|
+
WebAgent::Cookie.new(
|
38
|
+
:name => cookie.name,
|
39
|
+
:value => cookie.value,
|
40
|
+
:domain => cookie.domain,
|
41
|
+
:path => cookie.path,
|
42
|
+
:origin => cookie.origin,
|
43
|
+
:for_domain => cookie.for_domain,
|
44
|
+
:expires => cookie.expires,
|
45
|
+
:httponly => cookie.httponly,
|
46
|
+
:secure => cookie.secure
|
47
|
+
)
|
48
|
+
}
|
32
49
|
end
|
33
50
|
|
34
|
-
def
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
when /\d+\.\d+\.\d+\.\d+/
|
39
|
-
return (hostname == domainname)
|
40
|
-
when '.'
|
41
|
-
return true
|
42
|
-
when /^\./
|
43
|
-
# allows; host == rubyforge.org, domain == .rubyforge.org
|
44
|
-
return tail_match?(domainname, '.' + hostname)
|
45
|
-
else
|
46
|
-
return (hostname == domainname)
|
51
|
+
def cookie_value(uri)
|
52
|
+
cookies = self.cookies(uri)
|
53
|
+
unless cookies.empty?
|
54
|
+
HTTP::Cookie.cookie_value(cookies)
|
47
55
|
end
|
48
56
|
end
|
49
57
|
|
50
|
-
def
|
51
|
-
|
58
|
+
def parse(value, uri)
|
59
|
+
@jar.parse(value, uri)
|
52
60
|
end
|
53
61
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
attr_accessor :name, :value
|
60
|
-
attr_accessor :domain, :path
|
61
|
-
attr_accessor :expires ## for Netscape Cookie
|
62
|
-
attr_accessor :url
|
63
|
-
attr_writer :use, :secure, :discard, :domain_orig, :path_orig, :override
|
64
|
-
|
65
|
-
USE = 1
|
66
|
-
SECURE = 2
|
67
|
-
DOMAIN = 4
|
68
|
-
PATH = 8
|
69
|
-
DISCARD = 16
|
70
|
-
OVERRIDE = 32
|
71
|
-
OVERRIDE_OK = 32
|
72
|
-
|
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
|
79
|
-
|
80
|
-
def discard?
|
81
|
-
@discard
|
82
|
-
end
|
83
|
-
|
84
|
-
def use?
|
85
|
-
@use
|
86
|
-
end
|
87
|
-
|
88
|
-
def secure?
|
89
|
-
@secure
|
90
|
-
end
|
91
|
-
|
92
|
-
def domain_orig?
|
93
|
-
@domain_orig
|
94
|
-
end
|
95
|
-
|
96
|
-
def path_orig?
|
97
|
-
@path_orig
|
62
|
+
def cookies=(cookies)
|
63
|
+
@jar.clear
|
64
|
+
cookies.each do |cookie|
|
65
|
+
add(cookie)
|
66
|
+
end
|
98
67
|
end
|
99
68
|
|
100
|
-
def
|
101
|
-
@
|
69
|
+
def add(cookie)
|
70
|
+
@jar.add(cookie)
|
102
71
|
end
|
103
72
|
|
104
|
-
def
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
flg += PATH if @path_orig
|
110
|
-
flg += DISCARD if @discard
|
111
|
-
flg += OVERRIDE if @override
|
112
|
-
flg
|
73
|
+
def find(uri)
|
74
|
+
warning('CookieManager#find is deprecated and will be removed in near future. Use HTTP::Cookie.cookie_value(CookieManager#cookies) instead')
|
75
|
+
if cookie = cookies(uri)
|
76
|
+
HTTP::Cookie.cookie_value(cookie)
|
77
|
+
end
|
113
78
|
end
|
114
79
|
|
115
|
-
|
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
|
80
|
+
private
|
124
81
|
|
125
|
-
def
|
126
|
-
|
127
|
-
|
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
|
82
|
+
def check_cookies_file
|
83
|
+
unless @cookies_file
|
84
|
+
raise ArgumentError.new('Cookies file not specified')
|
134
85
|
end
|
135
86
|
end
|
87
|
+
end
|
136
88
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
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
|
89
|
+
class WebAgentSaver < HTTP::CookieJar::AbstractSaver
|
90
|
+
# no option
|
91
|
+
def default_options
|
92
|
+
{}
|
159
93
|
end
|
160
94
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
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
|
95
|
+
# same as HTTP::CookieJar::CookiestxtSaver
|
96
|
+
def save(io, jar)
|
97
|
+
jar.each { |cookie|
|
98
|
+
next if !@session && cookie.session?
|
99
|
+
io.print cookie_to_record(cookie)
|
194
100
|
}
|
195
101
|
end
|
196
102
|
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
value
|
103
|
+
# same as HTTP::CookieJar::CookiestxtSaver
|
104
|
+
def load(io, jar)
|
105
|
+
io.each_line { |line|
|
106
|
+
cookie = parse_record(line) and jar.add(cookie)
|
107
|
+
}
|
203
108
|
end
|
204
|
-
private :normalize_cookie_value
|
205
|
-
end
|
206
|
-
|
207
|
-
class CookieManager
|
208
|
-
include CookieUtils
|
209
109
|
|
210
|
-
|
211
|
-
class Error < StandardError; end
|
212
|
-
class ErrorOverrideOK < Error; end
|
213
|
-
class SpecialError < Error; end
|
110
|
+
private
|
214
111
|
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
@cookies.extend(MonitorMixin)
|
226
|
-
@cookies_file = file
|
227
|
-
@is_saved = true
|
228
|
-
@reject_domains = Array.new()
|
229
|
-
@accept_domains = Array.new()
|
230
|
-
@netscape_rule = false
|
112
|
+
def cookie_to_record(cookie)
|
113
|
+
[
|
114
|
+
cookie.origin,
|
115
|
+
cookie.name,
|
116
|
+
cookie.value,
|
117
|
+
cookie.expires.to_i,
|
118
|
+
cookie.dot_domain,
|
119
|
+
cookie.path,
|
120
|
+
self.class.flag(cookie)
|
121
|
+
].join("\t") + "\n"
|
231
122
|
end
|
232
123
|
|
233
|
-
def
|
234
|
-
|
235
|
-
|
236
|
-
end
|
124
|
+
def parse_record(line)
|
125
|
+
return nil if /\A#/ =~ line
|
126
|
+
col = line.chomp.split(/\t/)
|
237
127
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
(!cookie.discard? or save_discarded)
|
248
|
-
f.print(cookie.url.to_s,"\t",
|
249
|
-
cookie.name,"\t",
|
250
|
-
cookie.value,"\t",
|
251
|
-
cookie.expires.to_i,"\t",
|
252
|
-
cookie.domain,"\t",
|
253
|
-
cookie.path,"\t",
|
254
|
-
cookie.flag,"\n")
|
255
|
-
end
|
256
|
-
end
|
257
|
-
end
|
128
|
+
origin = col[0]
|
129
|
+
name = col[1]
|
130
|
+
value = col[2]
|
131
|
+
value.chomp!
|
132
|
+
if col[3].empty? or col[3] == '0'
|
133
|
+
expires = nil
|
134
|
+
else
|
135
|
+
expires = Time.at(col[3].to_i)
|
136
|
+
return nil if expires < Time.now
|
258
137
|
end
|
259
|
-
|
260
|
-
|
138
|
+
domain = col[4]
|
139
|
+
path = col[5]
|
261
140
|
|
262
|
-
|
263
|
-
|
141
|
+
cookie = WebAgent::Cookie.new(name, value,
|
142
|
+
:origin => origin,
|
143
|
+
:domain => domain,
|
144
|
+
:path => path,
|
145
|
+
:expires => expires
|
146
|
+
)
|
147
|
+
self.class.set_flag(cookie, col[6].to_i)
|
148
|
+
cookie
|
264
149
|
end
|
265
150
|
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
end
|
272
|
-
is_expired
|
273
|
-
}
|
274
|
-
end
|
151
|
+
USE = 1
|
152
|
+
SECURE = 2
|
153
|
+
DOMAIN = 4
|
154
|
+
PATH = 8
|
155
|
+
HTTP_ONLY = 64
|
275
156
|
|
276
|
-
def
|
277
|
-
|
278
|
-
|
279
|
-
|
157
|
+
def self.flag(cookie)
|
158
|
+
flg = 0
|
159
|
+
flg += USE # not used
|
160
|
+
flg += SECURE if cookie.secure?
|
161
|
+
flg += DOMAIN if cookie.for_domain?
|
162
|
+
flg += HTTP_ONLY if cookie.httponly?
|
163
|
+
flg += PATH if cookie.path # not used
|
164
|
+
flg
|
280
165
|
end
|
281
166
|
|
282
|
-
def
|
283
|
-
if
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
ret = ''
|
288
|
-
c = cookie_list.shift
|
289
|
-
ret += "#{c.name}=#{c.value}"
|
290
|
-
cookie_list.each{|cookie|
|
291
|
-
ret += "; #{cookie.name}=#{cookie.value}"
|
292
|
-
}
|
293
|
-
return ret
|
167
|
+
def self.set_flag(cookie, flag)
|
168
|
+
cookie.secure = true if flag & SECURE > 0
|
169
|
+
cookie.for_domain = true if flag & DOMAIN > 0
|
170
|
+
cookie.httponly = true if flag & HTTP_ONLY > 0
|
294
171
|
end
|
295
|
-
|
172
|
+
end
|
173
|
+
end
|
296
174
|
|
175
|
+
# for backward compatibility
|
176
|
+
class WebAgent
|
177
|
+
CookieManager = ::HTTPClient::CookieManager
|
297
178
|
|
298
|
-
|
299
|
-
|
179
|
+
class Cookie < HTTP::Cookie
|
180
|
+
include HTTPClient::Util
|
300
181
|
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
if cookie.use? && !is_expired && cookie.match?(url)
|
305
|
-
if cookie_list.select{|c1| c1.name == cookie.name}.empty?
|
306
|
-
cookie_list << cookie
|
307
|
-
end
|
308
|
-
end
|
309
|
-
}
|
310
|
-
return make_cookie_str(cookie_list)
|
182
|
+
def url
|
183
|
+
deprecated('url', 'origin')
|
184
|
+
self.origin
|
311
185
|
end
|
312
186
|
|
313
|
-
def
|
314
|
-
|
315
|
-
|
316
|
-
}
|
187
|
+
def url=(url)
|
188
|
+
deprecated('url=', 'origin=')
|
189
|
+
self.origin = url
|
317
190
|
end
|
318
|
-
private :find_cookie_info
|
319
191
|
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
raise err
|
324
|
-
end
|
192
|
+
def http_only?
|
193
|
+
deprecated('http_only?', 'httponly?')
|
194
|
+
self.httponly?
|
325
195
|
end
|
326
|
-
private :cookie_error
|
327
|
-
|
328
|
-
def add(cookie)
|
329
|
-
url = cookie.url
|
330
|
-
name, value = cookie.name, cookie.value
|
331
|
-
expires, domain, path =
|
332
|
-
cookie.expires, cookie.domain, cookie.path
|
333
|
-
secure, domain_orig, path_orig =
|
334
|
-
cookie.secure?, cookie.domain_orig?, cookie.path_orig?
|
335
|
-
discard, override =
|
336
|
-
cookie.discard?, cookie.override?
|
337
|
-
|
338
|
-
domainname = url.host
|
339
|
-
domain_orig, path_orig = domain, path
|
340
|
-
use_security = override
|
341
|
-
|
342
|
-
if domain
|
343
|
-
|
344
|
-
# [DRAFT 12] s. 4.2.2 (does not apply in the case that
|
345
|
-
# host name is the same as domain attribute for version 0
|
346
|
-
# cookie)
|
347
|
-
# I think that this rule has almost the same effect as the
|
348
|
-
# tail match of [NETSCAPE].
|
349
|
-
if domain !~ /^\./ && domainname != domain
|
350
|
-
domain = '.'+domain
|
351
|
-
end
|
352
|
-
|
353
|
-
# [NETSCAPE] rule
|
354
|
-
if @netscape_rule
|
355
|
-
n = total_dot_num(domain)
|
356
|
-
if n < 2
|
357
|
-
cookie_error(SpecialError.new(), override)
|
358
|
-
elsif n == 2
|
359
|
-
## [NETSCAPE] rule
|
360
|
-
ok = SPECIAL_DOMAIN.select{|sdomain|
|
361
|
-
sdomain == domain[-(sdomain.length)..-1]
|
362
|
-
}
|
363
|
-
if ok.empty?
|
364
|
-
cookie_error(SpecialError.new(), override)
|
365
|
-
end
|
366
|
-
end
|
367
|
-
end
|
368
|
-
|
369
|
-
# this implementation does not check RFC2109 4.3.2 case 2;
|
370
|
-
# the portion of host not in domain does not contain a dot.
|
371
|
-
# according to nsCookieService.cpp in Firefox 3.0.4, Firefox 3.0.4
|
372
|
-
# and IE does not check, too.
|
373
|
-
end
|
374
196
|
|
375
|
-
|
376
|
-
domain ||= domainname
|
377
|
-
@cookies.synchronize do
|
378
|
-
cookie = find_cookie_info(domain, path, name)
|
379
|
-
if !cookie
|
380
|
-
cookie = WebAgent::Cookie.new()
|
381
|
-
cookie.use = true
|
382
|
-
@cookies << cookie
|
383
|
-
end
|
384
|
-
check_expired_cookies()
|
385
|
-
end
|
197
|
+
alias original_domain domain
|
386
198
|
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
cookie.expires = expires
|
391
|
-
cookie.domain = domain
|
392
|
-
cookie.path = path
|
393
|
-
|
394
|
-
## for flag
|
395
|
-
cookie.secure = secure
|
396
|
-
cookie.domain_orig = domain_orig
|
397
|
-
cookie.path_orig = path_orig
|
398
|
-
if discard || cookie.expires == nil
|
399
|
-
cookie.discard = true
|
400
|
-
else
|
401
|
-
cookie.discard = false
|
402
|
-
@is_saved = false
|
403
|
-
end
|
199
|
+
def domain
|
200
|
+
warning('Cookie#domain returns dot-less domain name now. Use Cookie#dot_domain if you need "." at the beginning.')
|
201
|
+
self.original_domain
|
404
202
|
end
|
405
203
|
|
406
|
-
def
|
407
|
-
|
408
|
-
|
409
|
-
@cookies.clear
|
410
|
-
File.open(@cookies_file,'r'){|f|
|
411
|
-
while line = f.gets
|
412
|
-
cookie = WebAgent::Cookie.new()
|
413
|
-
@cookies << cookie
|
414
|
-
col = line.chomp.split(/\t/)
|
415
|
-
cookie.url = URI.parse(col[0])
|
416
|
-
cookie.name = col[1]
|
417
|
-
cookie.value = col[2]
|
418
|
-
if col[3].empty? or col[3] == '0'
|
419
|
-
cookie.expires = nil
|
420
|
-
else
|
421
|
-
cookie.expires = Time.at(col[3].to_i).gmtime
|
422
|
-
end
|
423
|
-
cookie.domain = col[4]
|
424
|
-
cookie.path = col[5]
|
425
|
-
cookie.set_flag(col[6])
|
426
|
-
end
|
427
|
-
}
|
428
|
-
end
|
204
|
+
def flag
|
205
|
+
deprecated('flag', 'secure, for_domain, etc.')
|
206
|
+
HTTPClient::WebAgentSaver.flag(self)
|
429
207
|
end
|
430
208
|
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
@accept_domains.each{|dom|
|
436
|
-
if domain_match(domain, dom)
|
437
|
-
return true
|
438
|
-
end
|
439
|
-
}
|
440
|
-
@reject_domains.each{|dom|
|
441
|
-
if domain_match(domain, dom)
|
442
|
-
return false
|
443
|
-
end
|
444
|
-
}
|
445
|
-
return true
|
209
|
+
private
|
210
|
+
|
211
|
+
def deprecated(old, new)
|
212
|
+
warning("WebAgent::Cookie is deprecated and will be replaced with HTTP::Cookie in the near future. Please use Cookie##{new} instead of Cookie##{old} for the replacement.")
|
446
213
|
end
|
447
214
|
end
|
448
215
|
end
|
449
216
|
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
454
|
-
== WebAgent::CookieManager Class
|
455
|
-
|
456
|
-
Load, save, parse and send cookies.
|
457
|
-
|
458
|
-
=== Usage
|
459
|
-
|
460
|
-
## initialize
|
461
|
-
cm = WebAgent::CookieManager.new("/home/foo/bar/cookie")
|
462
|
-
|
463
|
-
## load cookie data
|
464
|
-
cm.load_cookies()
|
465
|
-
|
466
|
-
## parse cookie from string (maybe "Set-Cookie:" header)
|
467
|
-
cm.parse(str)
|
468
|
-
|
469
|
-
## send cookie data to url
|
470
|
-
f.write(cm.find(url))
|
471
|
-
|
472
|
-
## save cookie to cookiefile
|
473
|
-
cm.save_cookies()
|
474
|
-
|
475
|
-
|
476
|
-
=== Class Methods
|
477
|
-
|
478
|
-
-- CookieManager::new(file=nil)
|
479
|
-
|
480
|
-
create new CookieManager. If a file is provided,
|
481
|
-
use it as cookies' file.
|
482
|
-
|
483
|
-
=== Methods
|
484
|
-
|
485
|
-
-- CookieManager#save_cookies(force = nil)
|
486
|
-
|
487
|
-
save cookies' data into file. if argument is true,
|
488
|
-
save data although data is not modified.
|
489
|
-
|
490
|
-
-- CookieManager#parse(str, url)
|
491
|
-
|
492
|
-
parse string and store cookie (to parse HTTP response header).
|
493
|
-
|
494
|
-
-- CookieManager#find(url)
|
495
|
-
|
496
|
-
get cookies and make into string (to send as HTTP request header).
|
497
|
-
|
498
|
-
-- CookieManager#add(cookie)
|
499
|
-
|
500
|
-
add new cookie.
|
501
|
-
|
502
|
-
-- CookieManager#load_cookies()
|
503
|
-
|
504
|
-
load cookies' data from file.
|
505
|
-
|
506
|
-
|
507
|
-
== WebAgent::CookieUtils Module
|
508
|
-
|
509
|
-
-- CookieUtils::head_match?(str1, str2)
|
510
|
-
-- CookieUtils::tail_match?(str1, str2)
|
511
|
-
-- CookieUtils::domain_match(host, domain)
|
512
|
-
-- CookieUtils::total_dot_num(str)
|
513
|
-
|
514
|
-
|
515
|
-
== WebAgent::Cookie Class
|
516
|
-
|
517
|
-
=== Class Methods
|
518
|
-
|
519
|
-
-- Cookie::new()
|
520
|
-
|
521
|
-
create new cookie.
|
522
|
-
|
523
|
-
=== Methods
|
524
|
-
|
525
|
-
-- Cookie#match?(url)
|
526
|
-
|
527
|
-
match cookie by url. if match, return true. otherwise,
|
528
|
-
return false.
|
529
|
-
|
530
|
-
-- Cookie#name
|
531
|
-
-- Cookie#name=(name)
|
532
|
-
-- Cookie#value
|
533
|
-
-- Cookie#value=(value)
|
534
|
-
-- Cookie#domain
|
535
|
-
-- Cookie#domain=(domain)
|
536
|
-
-- Cookie#path
|
537
|
-
-- Cookie#path=(path)
|
538
|
-
-- Cookie#expires
|
539
|
-
-- Cookie#expires=(expires)
|
540
|
-
-- Cookie#url
|
541
|
-
-- Cookie#url=(url)
|
542
|
-
|
543
|
-
accessor methods for cookie's items.
|
544
|
-
|
545
|
-
-- Cookie#discard?
|
546
|
-
-- Cookie#discard=(discard)
|
547
|
-
-- Cookie#use?
|
548
|
-
-- Cookie#use=(use)
|
549
|
-
-- Cookie#secure?
|
550
|
-
-- Cookie#secure=(secure)
|
551
|
-
-- Cookie#domain_orig?
|
552
|
-
-- Cookie#domain_orig=(domain_orig)
|
553
|
-
-- Cookie#path_orig?
|
554
|
-
-- Cookie#path_orig=(path_orig)
|
555
|
-
-- Cookie#override?
|
556
|
-
-- Cookie#override=(override)
|
557
|
-
-- Cookie#flag
|
558
|
-
-- Cookie#set_flag(flag_num)
|
559
|
-
|
560
|
-
accessor methods for flags.
|
561
|
-
|
562
|
-
=end
|
217
|
+
rescue LoadError
|
218
|
+
require 'httpclient/webagent-cookie'
|
219
|
+
end
|
220
|
+
end
|