http_request.rb 1.1.2 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- data/Changelog +6 -0
- data/README.rdoc +1 -1
- data/lib/http_request.rb +10 -7
- metadata +2 -2
data/Changelog
CHANGED
data/README.rdoc
CHANGED
data/lib/http_request.rb
CHANGED
@@ -11,9 +11,9 @@
|
|
11
11
|
#
|
12
12
|
# == Version
|
13
13
|
#
|
14
|
-
# v1.1.
|
14
|
+
# v1.1.4
|
15
15
|
#
|
16
|
-
# Last Change:
|
16
|
+
# Last Change: 16 Feb, 2010
|
17
17
|
#
|
18
18
|
# == Author
|
19
19
|
#
|
@@ -32,7 +32,7 @@ class HttpRequest
|
|
32
32
|
include Singleton
|
33
33
|
class << self
|
34
34
|
# version
|
35
|
-
VERSION = '1.1.
|
35
|
+
VERSION = '1.1.4'.freeze
|
36
36
|
def version;VERSION;end
|
37
37
|
|
38
38
|
# avaiabled http methods
|
@@ -97,6 +97,7 @@ class HttpRequest
|
|
97
97
|
|
98
98
|
# catch all available http requests
|
99
99
|
def self.method_missing(method_name, options, &block)
|
100
|
+
@@redirect_times = 0
|
100
101
|
# we need to retrieve the cookies from last http response before reset cookies if it's a Net::HTTPResponse
|
101
102
|
options[:cookies] = options[:cookies].cookies if options[:cookies].is_a? Net::HTTPResponse
|
102
103
|
@@__cookies = {}
|
@@ -276,8 +277,6 @@ class HttpRequest
|
|
276
277
|
end
|
277
278
|
@headers['Cookie'] = cookies unless cookies.empty?
|
278
279
|
end
|
279
|
-
|
280
|
-
@redirect_times = 0 if @options[:redirect]
|
281
280
|
end
|
282
281
|
|
283
282
|
# parse parameters for the options[:parameters] and @uri.query
|
@@ -387,6 +386,7 @@ class HttpRequest
|
|
387
386
|
case response
|
388
387
|
when Net::HTTPRedirection
|
389
388
|
url = "#{@uri.scheme}://#{@uri.host}#{':' + @uri.port.to_s if @uri.port != 80}"
|
389
|
+
last_url = @options[:url]
|
390
390
|
@options[:url] = case response['location']
|
391
391
|
when /^https?:\/\//i
|
392
392
|
response['location']
|
@@ -403,13 +403,16 @@ class HttpRequest
|
|
403
403
|
else
|
404
404
|
url + File.dirname(@uri.path) + '/' + response['location']
|
405
405
|
end
|
406
|
-
|
407
|
-
|
406
|
+
return data(response, &block) if @@redirect_times > 2 and @options[:url].eql? last_url
|
407
|
+
@@redirect_times += 1
|
408
|
+
raise 'too many redirects...' if @@redirect_times > @options[:redirect_limits]
|
408
409
|
if @options[:cookies].nil?
|
409
410
|
@options[:cookies] = self.class.cookies
|
410
411
|
else
|
411
412
|
@options[:cookies] = @options[:cookies].update self.class.cookies
|
412
413
|
end
|
414
|
+
@options.delete :parameters
|
415
|
+
@options.delete :method
|
413
416
|
request('get', @options, &block)
|
414
417
|
else
|
415
418
|
data(response, &block)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: http_request.rb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- xianhua.zhou
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date:
|
12
|
+
date: 2010-02-16 00:00:00 +08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|