typhoeus 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
data/lib/typhoeus.rb CHANGED
@@ -14,7 +14,7 @@ require 'typhoeus/request'
14
14
  require 'typhoeus/hydra'
15
15
 
16
16
  module Typhoeus
17
- VERSION = "0.1.12"
17
+ VERSION = "0.1.13"
18
18
 
19
19
  def self.easy_object_pool
20
20
  @easy_objects ||= []
data/lib/typhoeus/easy.rb CHANGED
@@ -16,7 +16,8 @@ module Typhoeus
16
16
  :CURLOPT_TIMEOUT_MS => 155,
17
17
  :CURLOPT_NOSIGNAL => 99,
18
18
  :CURLOPT_HTTPHEADER => 10023,
19
- :CURLOPT_FOLLOWLOCATION => 52
19
+ :CURLOPT_FOLLOWLOCATION => 52,
20
+ :CURLOPT_MAXREDIRS => 68
20
21
  }
21
22
  INFO_VALUES = {
22
23
  :CURLINFO_RESPONSE_CODE => 2097154,
@@ -48,6 +49,10 @@ module Typhoeus
48
49
  set_option(OPTION_VALUES[:CURLOPT_FOLLOWLOCATION], 0)
49
50
  end
50
51
  end
52
+
53
+ def max_redirects=(redirects)
54
+ set_option(OPTION_VALUES[:CURLOPT_MAXREDIRS], redirects)
55
+ end
51
56
 
52
57
  def timeout=(milliseconds)
53
58
  @timeout = milliseconds
@@ -123,6 +123,7 @@ module Typhoeus
123
123
  easy.request_body = request.body if request.body
124
124
  easy.timeout = request.timeout if request.timeout
125
125
  easy.follow_location = request.follow_location if request.follow_location
126
+ easy.max_redirects = request.max_redirects if request.max_redirects
126
127
  easy.on_success do |easy|
127
128
  queue_next
128
129
  handle_request(request, response_from_easy(easy, request))
@@ -1,6 +1,6 @@
1
1
  module Typhoeus
2
2
  class Request
3
- attr_accessor :method, :params, :body, :headers, :timeout, :user_agent, :response, :cache_timeout, :follow_location
3
+ attr_accessor :method, :params, :body, :headers, :timeout, :user_agent, :response, :cache_timeout, :follow_location, :max_redirects
4
4
  attr_reader :url
5
5
 
6
6
  def initialize(url, options = {})
@@ -12,6 +12,7 @@ module Typhoeus
12
12
  @user_agent = options[:user_agent] || Typhoeus::USER_AGENT
13
13
  @cache_timeout = options[:cache_timeout]
14
14
  @follow_location = options[:follow_location]
15
+ @max_redirects = options[:max_redirects]
15
16
  if @method == :post
16
17
  @url = url
17
18
  else
data/spec/servers/app.rb CHANGED
@@ -21,6 +21,10 @@ get '/redirect' do
21
21
  redirect '/'
22
22
  end
23
23
 
24
+ get '/bad_redirect' do
25
+ redirect '/bad_redirect'
26
+ end
27
+
24
28
  get '/**' do
25
29
  sleep params["delay"].to_i if params.has_key?("delay")
26
30
  request.env.merge!(:body => request.body.read).to_json
@@ -39,6 +39,26 @@ describe Typhoeus::Easy do
39
39
  # this doesn't work on a mac for some reason
40
40
  # e.timed_out?.should == true
41
41
  end
42
+
43
+ it "should allow the setting of the max redirects to follow" do
44
+ e = Typhoeus::Easy.new
45
+ e.url = "http://localhost:3001/redirect"
46
+ e.method = :get
47
+ e.follow_location = true
48
+ e.max_redirects = 5
49
+ e.perform
50
+ e.response_code.should == 200
51
+ end
52
+
53
+ it "should handle our bad redirect action, provided we've set max_redirects properly" do
54
+ e = Typhoeus::Easy.new
55
+ e.url = "http://localhost:3001/bad_redirect"
56
+ e.method = :get
57
+ e.follow_location = true
58
+ e.max_redirects = 5
59
+ e.perform
60
+ e.response_code.should == 302
61
+ end
42
62
  end
43
63
 
44
64
  describe "get" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: typhoeus
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Dix