httpclient 2.5.3.1 → 2.5.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/httpclient.rb +4 -4
- data/lib/httpclient/cookie.rb +77 -68
- data/lib/httpclient/http.rb +0 -4
- data/lib/httpclient/session.rb +1 -1
- data/lib/httpclient/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2ed970a9f9a678a4e9ffc7db66c03b06c1a6ca55
|
4
|
+
data.tar.gz: cb2835e9852021421d95449c0551679c6533571d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1329315ea58bed3ccadd8172b06b1556f63ad2e1d6582ad81ac749717ab68bffc41c0bff83e72df8c3f99c5a9823eee5f28ee9ee6b06e5ae829fa4a8ffd69cd1
|
7
|
+
data.tar.gz: 2e23832e6b2a0aef542f76887c2f5f488218b4c721e58b94b8c828e58b11ec1fca7384c2022d3ccaa77e0ef8a43d6eed3eade51c913d68c846e8c81cc42741d1
|
data/lib/httpclient.rb
CHANGED
@@ -958,7 +958,7 @@ private
|
|
958
958
|
body.pos = pos if pos
|
959
959
|
req = create_request(method, uri, query, body, header)
|
960
960
|
begin
|
961
|
-
protect_keep_alive_disconnected
|
961
|
+
protect_keep_alive_disconnected do
|
962
962
|
do_get_block(req, proxy, conn, &block)
|
963
963
|
end
|
964
964
|
res = conn.pop
|
@@ -984,7 +984,7 @@ private
|
|
984
984
|
body.pos = pos if pos
|
985
985
|
req = create_request(method, uri, query, body, header)
|
986
986
|
begin
|
987
|
-
protect_keep_alive_disconnected
|
987
|
+
protect_keep_alive_disconnected do
|
988
988
|
do_get_stream(req, proxy, tconn)
|
989
989
|
end
|
990
990
|
break
|
@@ -1054,14 +1054,14 @@ private
|
|
1054
1054
|
end
|
1055
1055
|
end
|
1056
1056
|
|
1057
|
-
def protect_keep_alive_disconnected
|
1057
|
+
def protect_keep_alive_disconnected
|
1058
1058
|
begin
|
1059
1059
|
yield
|
1060
1060
|
rescue KeepAliveDisconnected => e
|
1061
1061
|
if e.sess
|
1062
1062
|
@session_manager.invalidate(e.sess.dest)
|
1063
1063
|
end
|
1064
|
-
yield
|
1064
|
+
yield
|
1065
1065
|
end
|
1066
1066
|
end
|
1067
1067
|
|
data/lib/httpclient/cookie.rb
CHANGED
@@ -25,9 +25,9 @@ class WebAgent
|
|
25
25
|
|
26
26
|
def tail_match?(str1, str2)
|
27
27
|
if str1.length > 0
|
28
|
-
|
28
|
+
str1 == str2[-str1.length..-1].to_s
|
29
29
|
else
|
30
|
-
|
30
|
+
true
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
@@ -37,14 +37,14 @@ class WebAgent
|
|
37
37
|
hostname = host.sub(/\.\z/, '').downcase
|
38
38
|
case domain
|
39
39
|
when /\d+\.\d+\.\d+\.\d+/
|
40
|
-
|
41
|
-
when '.'
|
42
|
-
|
40
|
+
return (hostname == domainname)
|
41
|
+
when '.'
|
42
|
+
return true
|
43
43
|
when /^\./
|
44
44
|
# allows; host == rubyforge.org, domain == .rubyforge.org
|
45
|
-
|
45
|
+
return tail_match?(domainname, '.' + hostname)
|
46
46
|
else
|
47
|
-
|
47
|
+
return (hostname == domainname)
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
@@ -128,12 +128,12 @@ class WebAgent
|
|
128
128
|
def match?(url)
|
129
129
|
domainname = url.host
|
130
130
|
if (!domainname ||
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
131
|
+
!domain_match(domainname, @domain) ||
|
132
|
+
(@path && !head_match?(@path, url.path.empty? ? '/' : url.path)) ||
|
133
|
+
(@secure && (url.scheme != 'https')) )
|
134
|
+
return false
|
135
135
|
else
|
136
|
-
|
136
|
+
return true
|
137
137
|
end
|
138
138
|
end
|
139
139
|
|
@@ -141,22 +141,22 @@ class WebAgent
|
|
141
141
|
ret = Array.new
|
142
142
|
old_elem = nil
|
143
143
|
array.each{|elem|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
144
|
+
if (elem.scan(/"/).length % 2) == 0
|
145
|
+
if old_elem
|
146
|
+
old_elem << sep << elem
|
147
|
+
else
|
148
|
+
ret << elem
|
149
|
+
old_elem = nil
|
150
|
+
end
|
151
|
+
else
|
152
|
+
if old_elem
|
153
|
+
old_elem << sep << elem
|
154
|
+
ret << old_elem
|
155
|
+
old_elem = nil
|
156
|
+
else
|
157
|
+
old_elem = elem.dup
|
158
|
+
end
|
159
|
+
end
|
160
160
|
}
|
161
161
|
ret
|
162
162
|
end
|
@@ -169,37 +169,37 @@ class WebAgent
|
|
169
169
|
cookie_elem -= [""] # del empty elements, a cookie might included ";;"
|
170
170
|
first_elem = cookie_elem.shift
|
171
171
|
if first_elem !~ /([^=]*)(\=(.*))?/
|
172
|
-
|
173
|
-
|
172
|
+
return
|
173
|
+
## raise ArgumentError 'invalid cookie value'
|
174
174
|
end
|
175
175
|
@name = $1.strip
|
176
176
|
@value = normalize_cookie_value($3)
|
177
177
|
cookie_elem.each{|pair|
|
178
|
-
|
179
|
-
|
178
|
+
key, value = pair.split(/=/, 2) ## value may nil
|
179
|
+
key.strip!
|
180
180
|
value = normalize_cookie_value(value)
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
181
|
+
case key.downcase
|
182
|
+
when 'domain'
|
183
|
+
@domain = value
|
184
|
+
when 'expires'
|
185
185
|
@expires = nil
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
186
|
+
begin
|
187
|
+
@expires = Time.parse(value).gmtime if value
|
188
|
+
rescue ArgumentError
|
189
|
+
end
|
190
|
+
when 'path'
|
191
|
+
@path = value
|
192
|
+
when 'secure'
|
193
|
+
@secure = true ## value may nil, but must 'true'.
|
194
|
+
when 'httponly'
|
195
|
+
@http_only = true ## value may nil, but must 'true'.
|
196
|
+
else
|
197
197
|
warn("Unknown key: #{key} = #{value}")
|
198
|
-
|
198
|
+
end
|
199
199
|
}
|
200
200
|
end
|
201
201
|
|
202
|
-
|
202
|
+
private
|
203
203
|
|
204
204
|
def normalize_cookie_value(value)
|
205
205
|
if value
|
@@ -210,6 +210,13 @@ class WebAgent
|
|
210
210
|
end
|
211
211
|
end
|
212
212
|
|
213
|
+
##
|
214
|
+
# An Array class that already includes the MonitorMixin module.
|
215
|
+
#
|
216
|
+
class SynchronizedArray < Array
|
217
|
+
include MonitorMixin
|
218
|
+
end
|
219
|
+
|
213
220
|
class CookieManager
|
214
221
|
include CookieUtils
|
215
222
|
|
@@ -223,8 +230,7 @@ class WebAgent
|
|
223
230
|
attr_accessor :accept_domains, :reject_domains
|
224
231
|
|
225
232
|
def initialize(file=nil)
|
226
|
-
@cookies =
|
227
|
-
@cookies.extend(MonitorMixin)
|
233
|
+
@cookies = SynchronizedArray.new
|
228
234
|
@cookies_file = file
|
229
235
|
@is_saved = true
|
230
236
|
@reject_domains = Array.new
|
@@ -233,8 +239,11 @@ class WebAgent
|
|
233
239
|
end
|
234
240
|
|
235
241
|
def cookies=(cookies)
|
236
|
-
|
237
|
-
|
242
|
+
if cookies.is_a?(SynchronizedArray)
|
243
|
+
@cookies = cookies
|
244
|
+
else
|
245
|
+
@cookies = SynchronizedArray.new(cookies)
|
246
|
+
end
|
238
247
|
end
|
239
248
|
|
240
249
|
def save_all_cookies(force = nil, save_unused = true, save_discarded = true)
|
@@ -246,7 +255,7 @@ class WebAgent
|
|
246
255
|
File.open(@cookies_file, 'w') do |f|
|
247
256
|
@cookies.each do |cookie|
|
248
257
|
if (cookie.use? or save_unused) and
|
249
|
-
|
258
|
+
(!cookie.discard? or save_discarded)
|
250
259
|
f.print(cookie.url.to_s,"\t",
|
251
260
|
cookie.name,"\t",
|
252
261
|
cookie.value,"\t",
|
@@ -327,10 +336,10 @@ class WebAgent
|
|
327
336
|
cookie.path_orig = given.path
|
328
337
|
|
329
338
|
if cookie.discard? || cookie.expires == nil
|
330
|
-
|
339
|
+
cookie.discard = true
|
331
340
|
else
|
332
|
-
|
333
|
-
|
341
|
+
cookie.discard = false
|
342
|
+
@is_saved = false
|
334
343
|
end
|
335
344
|
end
|
336
345
|
|
@@ -362,33 +371,33 @@ class WebAgent
|
|
362
371
|
# Who use it?
|
363
372
|
def check_cookie_accept_domain(domain)
|
364
373
|
unless domain
|
365
|
-
|
374
|
+
return false
|
366
375
|
end
|
367
376
|
@accept_domains.each{|dom|
|
368
|
-
|
369
|
-
|
370
|
-
|
377
|
+
if domain_match(domain, dom)
|
378
|
+
return true
|
379
|
+
end
|
371
380
|
}
|
372
381
|
@reject_domains.each{|dom|
|
373
|
-
|
374
|
-
|
375
|
-
|
382
|
+
if domain_match(domain, dom)
|
383
|
+
return false
|
384
|
+
end
|
376
385
|
}
|
377
386
|
return true
|
378
387
|
end
|
379
388
|
|
380
|
-
|
389
|
+
private
|
381
390
|
|
382
391
|
def make_cookie_str(cookie_list)
|
383
392
|
if cookie_list.empty?
|
384
|
-
|
393
|
+
return nil
|
385
394
|
end
|
386
395
|
|
387
396
|
ret = ''
|
388
397
|
c = cookie_list.shift
|
389
398
|
ret += "#{c.name}=#{c.value}"
|
390
399
|
cookie_list.each{|cookie|
|
391
|
-
|
400
|
+
ret += "; #{cookie.name}=#{cookie.value}"
|
392
401
|
}
|
393
402
|
return ret
|
394
403
|
end
|
@@ -432,7 +441,7 @@ class WebAgent
|
|
432
441
|
# not tested well; used only netscape_rule = true.
|
433
442
|
def cookie_error(err, override)
|
434
443
|
if !err.kind_of?(ErrorOverrideOK) || !override
|
435
|
-
|
444
|
+
raise err
|
436
445
|
end
|
437
446
|
end
|
438
447
|
end
|
data/lib/httpclient/http.rb
CHANGED
data/lib/httpclient/session.rb
CHANGED
@@ -200,7 +200,7 @@ class HTTPClient
|
|
200
200
|
# each session.
|
201
201
|
def get_session(req, via_proxy = false)
|
202
202
|
site = Site.new(req.header.request_uri)
|
203
|
-
if
|
203
|
+
if cached = get_cached_session(site)
|
204
204
|
cached
|
205
205
|
else
|
206
206
|
open(req.header.request_uri, via_proxy)
|
data/lib/httpclient/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: httpclient
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.5.3.
|
4
|
+
version: 2.5.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hiroshi Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description:
|
14
14
|
email: nahi@ruby-lang.org
|