Permalink
Browse files

updated for the v1.1.3

  • Loading branch information...
1 parent 1d3ae5c commit 4b16c324def0bb11b50d05a415f5d9f67604db2a zhou xianhua committed Dec 29, 2009
Showing with 13 additions and 8 deletions.
  1. +3 −0 Changelog
  2. +1 −1 http_request.gemspec
  3. +9 −7 lib/http_request.rb
View
3 Changelog
@@ -1,3 +1,6 @@
+v1.1.3
+ * fixed a bug of the number of redirection checking
+
v1.1.2
* fixed a bug of redirection
View
2 http_request.gemspec
@@ -3,7 +3,7 @@ SPEC=Gem::Specification.new do |s|
s.homepage = 'http://my.cnzxh.net'
s.rubyforge_project = "http_request.rb"
s.name = 'http_request.rb'
- s.version = '1.1.2'
+ s.version = '1.1.3'
s.author = 'xianhua.zhou'
s.email = 'xianhua.zhou@gmail.com'
s.platform = Gem::Platform::RUBY
View
16 lib/http_request.rb
@@ -11,9 +11,9 @@
#
# == Version
#
-# v1.1.2
+# v1.1.3
#
-# Last Change: 15 Oct, 2009
+# Last Change: 29 Dec, 2009
#
# == Author
#
@@ -32,7 +32,7 @@ class HttpRequest
include Singleton
class << self
# version
- VERSION = '1.1.2'.freeze
+ VERSION = '1.1.3'.freeze
def version;VERSION;end
# avaiabled http methods
@@ -97,6 +97,7 @@ def request(method, options, &block)
# catch all available http requests
def self.method_missing(method_name, options, &block)
+ @@redirect_times = 0
# we need to retrieve the cookies from last http response before reset cookies if it's a Net::HTTPResponse
options[:cookies] = options[:cookies].cookies if options[:cookies].is_a? Net::HTTPResponse
@@__cookies = {}
@@ -276,8 +277,6 @@ def parse_options(method, options)
end
@headers['Cookie'] = cookies unless cookies.empty?
end
-
- @redirect_times = 0 if @options[:redirect]
end
# parse parameters for the options[:parameters] and @uri.query
@@ -387,6 +386,7 @@ def process_redirection(response, &block)
case response
when Net::HTTPRedirection
url = "#{@uri.scheme}://#{@uri.host}#{':' + @uri.port.to_s if @uri.port != 80}"
+ last_url = @options[:url]
@options[:url] = case response['location']
when /^https?:\/\//i
response['location']
@@ -403,13 +403,15 @@ def process_redirection(response, &block)
else
url + File.dirname(@uri.path) + '/' + response['location']
end
- @redirect_times = @redirect_times.succ
- raise 'too many redirects...' if @redirect_times > @options[:redirect_limits]
+ return data(response, &block) if @@redirect_times > 2 and @options[:url].eql? last_url
+ @@redirect_times += 1
+ raise 'too many redirects...' if @@redirect_times > @options[:redirect_limits]
if @options[:cookies].nil?
@options[:cookies] = self.class.cookies
else
@options[:cookies] = @options[:cookies].update self.class.cookies
end
+ @options.delete :parameters
request('get', @options, &block)
else
data(response, &block)

0 comments on commit 4b16c32

Please sign in to comment.