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 +1 -1
- data/lib/typhoeus/easy.rb +6 -1
- data/lib/typhoeus/hydra.rb +1 -0
- data/lib/typhoeus/request.rb +2 -1
- data/spec/servers/app.rb +4 -0
- data/spec/typhoeus/easy_spec.rb +20 -0
- metadata +1 -1
data/lib/typhoeus.rb
CHANGED
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
|
data/lib/typhoeus/hydra.rb
CHANGED
@@ -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))
|
data/lib/typhoeus/request.rb
CHANGED
@@ -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
data/spec/typhoeus/easy_spec.rb
CHANGED
@@ -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
|