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.
Files changed (4) hide show
  1. data/Changelog +6 -0
  2. data/README.rdoc +1 -1
  3. data/lib/http_request.rb +10 -7
  4. metadata +2 -2
data/Changelog CHANGED
@@ -1,3 +1,9 @@
1
+ v1.1.4
2
+ * always use "get" method for redirection
3
+
4
+ v1.1.3
5
+ * fixed a bug of the number of redirection checking
6
+
1
7
  v1.1.2
2
8
  * fixed a bug of redirection
3
9
 
data/README.rdoc CHANGED
@@ -227,7 +227,7 @@ download multiple files from a directory
227
227
  bug fixing, testing and testing...
228
228
 
229
229
  == LATEST VERSION
230
- 1.1.2
230
+ 1.1.4
231
231
 
232
232
  == Author
233
233
 
data/lib/http_request.rb CHANGED
@@ -11,9 +11,9 @@
11
11
  #
12
12
  # == Version
13
13
  #
14
- # v1.1.2
14
+ # v1.1.4
15
15
  #
16
- # Last Change: 15 Oct, 2009
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.2'.freeze
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
- @redirect_times = @redirect_times.succ
407
- raise 'too many redirects...' if @redirect_times > @options[:redirect_limits]
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.2
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: 2009-11-26 00:00:00 +08:00
12
+ date: 2010-02-16 00:00:00 +08:00
13
13
  default_executable:
14
14
  dependencies: []
15
15