typhoeus 0.1.11 → 0.1.12
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/hydra.rb +1 -0
- data/lib/typhoeus/request.rb +3 -2
- data/spec/servers/app.rb +4 -0
- data/spec/typhoeus/easy_spec.rb +28 -2
- metadata +1 -1
data/lib/typhoeus.rb
CHANGED
data/lib/typhoeus/hydra.rb
CHANGED
@@ -122,6 +122,7 @@ module Typhoeus
|
|
122
122
|
easy.headers = request.headers if request.headers
|
123
123
|
easy.request_body = request.body if request.body
|
124
124
|
easy.timeout = request.timeout if request.timeout
|
125
|
+
easy.follow_location = request.follow_location if request.follow_location
|
125
126
|
easy.on_success do |easy|
|
126
127
|
queue_next
|
127
128
|
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
|
3
|
+
attr_accessor :method, :params, :body, :headers, :timeout, :user_agent, :response, :cache_timeout, :follow_location
|
4
4
|
attr_reader :url
|
5
5
|
|
6
6
|
def initialize(url, options = {})
|
@@ -11,6 +11,7 @@ module Typhoeus
|
|
11
11
|
@headers = options[:headers] || {}
|
12
12
|
@user_agent = options[:user_agent] || Typhoeus::USER_AGENT
|
13
13
|
@cache_timeout = options[:cache_timeout]
|
14
|
+
@follow_location = options[:follow_location]
|
14
15
|
if @method == :post
|
15
16
|
@url = url
|
16
17
|
else
|
@@ -112,4 +113,4 @@ module Typhoeus
|
|
112
113
|
run(url, params.merge(:method => :delete))
|
113
114
|
end
|
114
115
|
end
|
115
|
-
end
|
116
|
+
end
|
data/spec/servers/app.rb
CHANGED
data/spec/typhoeus/easy_spec.rb
CHANGED
@@ -2,8 +2,34 @@ require File.dirname(__FILE__) + '/../spec_helper'
|
|
2
2
|
|
3
3
|
describe Typhoeus::Easy do
|
4
4
|
describe "options" do
|
5
|
-
it "should
|
6
|
-
|
5
|
+
it "should not follow redirects if not instructed to" do
|
6
|
+
e = Typhoeus::Easy.new
|
7
|
+
e.url = "http://localhost:3001/redirect"
|
8
|
+
e.method = :get
|
9
|
+
e.perform
|
10
|
+
e.response_code.should == 302
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should allow for following redirects" do
|
14
|
+
e = Typhoeus::Easy.new
|
15
|
+
e.url = "http://localhost:3001/redirect"
|
16
|
+
e.method = :get
|
17
|
+
e.follow_location = true
|
18
|
+
e.perform
|
19
|
+
e.response_code.should == 200
|
20
|
+
JSON.parse(e.response_body)["REQUEST_METHOD"].should == "GET"
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should allow you to set the user agent" do
|
24
|
+
easy = Typhoeus::Easy.new
|
25
|
+
easy.url = "http://localhost:3002"
|
26
|
+
easy.method = :get
|
27
|
+
easy.user_agent = "myapp"
|
28
|
+
easy.perform
|
29
|
+
easy.response_code.should == 200
|
30
|
+
JSON.parse(easy.response_body)["HTTP_USER_AGENT"].should == "myapp"
|
31
|
+
end
|
32
|
+
|
7
33
|
it "should provide a timeout in milliseconds" do
|
8
34
|
e = Typhoeus::Easy.new
|
9
35
|
e.url = "http://localhost:3001"
|