typhoeus 0.6.3 → 0.6.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/.gitignore +8 -0
- data/.rspec +4 -0
- data/.travis.yml +10 -0
- data/CHANGELOG.md +7 -1
- data/CONTRIBUTING.md +16 -0
- data/Guardfile +9 -0
- data/README.md +303 -1
- data/UPGRADE.md +55 -0
- data/lib/rack/typhoeus/middleware/params_decoder.rb +1 -1
- data/lib/rack/typhoeus/middleware/params_decoder/helper.rb +6 -2
- data/lib/typhoeus/adapters/faraday.rb +4 -1
- data/lib/typhoeus/easy_factory.rb +36 -15
- data/lib/typhoeus/hydra/before.rb +2 -1
- data/lib/typhoeus/hydra/cacheable.rb +1 -0
- data/lib/typhoeus/hydra/memoizable.rb +1 -0
- data/lib/typhoeus/hydra/queueable.rb +15 -3
- data/lib/typhoeus/request.rb +6 -2
- data/lib/typhoeus/request/marshal.rb +3 -2
- data/lib/typhoeus/response/informations.rb +4 -0
- data/lib/typhoeus/version.rb +1 -1
- data/perf/profile.rb +14 -0
- data/perf/vs_nethttp.rb +64 -0
- data/spec/rack/typhoeus/middleware/params_decoder/helper_spec.rb +132 -0
- data/spec/rack/typhoeus/middleware/params_decoder_spec.rb +31 -0
- data/spec/spec_helper.rb +35 -0
- data/spec/support/localhost_server.rb +94 -0
- data/spec/support/server.rb +108 -0
- data/spec/typhoeus/adapters/faraday_spec.rb +245 -0
- data/spec/typhoeus/config_spec.rb +15 -0
- data/spec/typhoeus/easy_factory_spec.rb +96 -0
- data/spec/typhoeus/errors/no_stub_spec.rb +13 -0
- data/spec/typhoeus/expectation_spec.rb +273 -0
- data/spec/typhoeus/hydra/addable_spec.rb +22 -0
- data/spec/typhoeus/hydra/before_spec.rb +97 -0
- data/spec/typhoeus/hydra/block_connection_spec.rb +18 -0
- data/spec/typhoeus/hydra/cacheable_spec.rb +68 -0
- data/spec/typhoeus/hydra/memoizable_spec.rb +53 -0
- data/spec/typhoeus/hydra/queueable_spec.rb +34 -0
- data/spec/typhoeus/hydra/runnable_spec.rb +155 -0
- data/spec/typhoeus/hydra/stubbable_spec.rb +28 -0
- data/spec/typhoeus/hydra_spec.rb +26 -0
- data/spec/typhoeus/pool_spec.rb +79 -0
- data/spec/typhoeus/request/actions_spec.rb +19 -0
- data/spec/typhoeus/request/before_spec.rb +92 -0
- data/spec/typhoeus/request/block_connection_spec.rb +75 -0
- data/spec/typhoeus/request/cacheable_spec.rb +80 -0
- data/spec/typhoeus/request/callbacks_spec.rb +91 -0
- data/spec/typhoeus/request/marshal_spec.rb +62 -0
- data/spec/typhoeus/request/memoizable_spec.rb +34 -0
- data/spec/typhoeus/request/operations_spec.rb +70 -0
- data/spec/typhoeus/request/responseable_spec.rb +13 -0
- data/spec/typhoeus/request/stubbable_spec.rb +27 -0
- data/spec/typhoeus/request_spec.rb +131 -0
- data/spec/typhoeus/response/header_spec.rb +97 -0
- data/spec/typhoeus/response/informations_spec.rb +218 -0
- data/spec/typhoeus/response/status_spec.rb +218 -0
- data/spec/typhoeus/response_spec.rb +81 -0
- data/spec/typhoeus_spec.rb +105 -0
- data/typhoeus.gemspec +25 -0
- metadata +101 -27
@@ -0,0 +1,70 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Typhoeus::Request::Operations do
|
4
|
+
let(:base_url) { "localhost:3001" }
|
5
|
+
let(:options) { {} }
|
6
|
+
let(:request) { Typhoeus::Request.new(base_url, options) }
|
7
|
+
|
8
|
+
describe "#run" do
|
9
|
+
let(:easy) { Ethon::Easy.new }
|
10
|
+
before { Typhoeus::Pool.should_receive(:get).and_return(easy) }
|
11
|
+
|
12
|
+
it "grabs an easy" do
|
13
|
+
request.run
|
14
|
+
end
|
15
|
+
|
16
|
+
it "generates settings" do
|
17
|
+
easy.should_receive(:http_request)
|
18
|
+
request.run
|
19
|
+
end
|
20
|
+
|
21
|
+
it "performs" do
|
22
|
+
easy.should_receive(:perform)
|
23
|
+
request.run
|
24
|
+
end
|
25
|
+
|
26
|
+
it "sets response" do
|
27
|
+
request.run
|
28
|
+
expect(request.response).to be
|
29
|
+
end
|
30
|
+
|
31
|
+
it "releases easy" do
|
32
|
+
Typhoeus::Pool.should_receive(:release)
|
33
|
+
request.run
|
34
|
+
end
|
35
|
+
|
36
|
+
it "calls on_complete" do
|
37
|
+
callback = double(:call)
|
38
|
+
callback.should_receive(:call)
|
39
|
+
request.instance_variable_set(:@on_complete, [callback])
|
40
|
+
request.run
|
41
|
+
end
|
42
|
+
|
43
|
+
it "returns a response" do
|
44
|
+
expect(request.run).to be_a(Typhoeus::Response)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
describe "#finish" do
|
49
|
+
let(:response) { Typhoeus::Response.new }
|
50
|
+
|
51
|
+
it "assigns response" do
|
52
|
+
request.finish(response)
|
53
|
+
expect(request.response).to be(response)
|
54
|
+
end
|
55
|
+
|
56
|
+
it "assigns request to response" do
|
57
|
+
request.finish(response)
|
58
|
+
expect(request.response.request).to be(request)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "executes callbacks" do
|
62
|
+
request.should_receive(:execute_callbacks)
|
63
|
+
request.finish(response)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "returns response" do
|
67
|
+
expect(request.finish(response)).to be(response)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Typhoeus::Request::Responseable do
|
4
|
+
let(:request) { Typhoeus::Request.new("base_url", {}) }
|
5
|
+
let(:response) { Typhoeus::Response.new }
|
6
|
+
|
7
|
+
describe "#response=" do
|
8
|
+
it "stores response" do
|
9
|
+
request.response = response
|
10
|
+
expect(request.response).to eq(response)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Typhoeus::Request::Stubbable do
|
4
|
+
let(:base_url) { "localhost:3001" }
|
5
|
+
let(:request) { Typhoeus::Request.new(base_url) }
|
6
|
+
let(:response) { Typhoeus::Response.new }
|
7
|
+
|
8
|
+
before { Typhoeus.stub(base_url).and_return(response) }
|
9
|
+
|
10
|
+
describe "#run" do
|
11
|
+
it "checks expectations" do
|
12
|
+
request.run
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when expectation found" do
|
16
|
+
it "finishes request" do
|
17
|
+
request.should_receive(:finish)
|
18
|
+
request.run
|
19
|
+
end
|
20
|
+
|
21
|
+
it "sets mock on response" do
|
22
|
+
request.run
|
23
|
+
expect(request.response.mock).to be(true)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,131 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Typhoeus::Request do
|
4
|
+
let(:base_url) { "localhost:3001" }
|
5
|
+
let(:options) { {:verbose => true, :headers => { 'User-Agent' => "Fubar" }} }
|
6
|
+
let(:request) { Typhoeus::Request.new(base_url, options) }
|
7
|
+
|
8
|
+
describe ".url" do
|
9
|
+
context "when no parameters" do
|
10
|
+
it "returns base_url" do
|
11
|
+
expect(request.url).to eq(request.base_url)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
context "when parameters" do
|
16
|
+
let(:options) { {:params => {:a => 1}} }
|
17
|
+
|
18
|
+
it "returns full url" do
|
19
|
+
expect(request.url).to eq("#{request.base_url}?a=1")
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
it "pushes an easy back into the pool" do
|
24
|
+
easy = double.as_null_object
|
25
|
+
Typhoeus::Pool.stub(:get).and_return(easy)
|
26
|
+
Typhoeus::Pool.should_receive(:release).with(easy)
|
27
|
+
request.url
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe ".new" do
|
32
|
+
it "stores base_url" do
|
33
|
+
expect(request.base_url).to eq(base_url)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "stores options" do
|
37
|
+
expect(request.options).to eq(options)
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when header with user agent" do
|
41
|
+
let(:options) { {:headers => {'User-Agent' => "Custom"} } }
|
42
|
+
|
43
|
+
it "doesn't modify user agent" do
|
44
|
+
expect(request.options[:headers]['User-Agent']).to eq("Custom")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
context "when header without user agent" do
|
49
|
+
let(:options) { {:headers => {} } }
|
50
|
+
|
51
|
+
it "add user agent" do
|
52
|
+
expect(request.options[:headers]['User-Agent']).to eq(Typhoeus::USER_AGENT)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when Config.verbose set" do
|
57
|
+
before { Typhoeus.configure { |config| config.verbose = true} }
|
58
|
+
after { Typhoeus.configure { |config| config.verbose = false} }
|
59
|
+
|
60
|
+
it "respects" do
|
61
|
+
expect(request.options[:verbose]).to be_true
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe "#eql?" do
|
67
|
+
context "when another class" do
|
68
|
+
let(:other) { "" }
|
69
|
+
|
70
|
+
it "returns false" do
|
71
|
+
expect(request).to_not eql other
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
context "when same class" do
|
76
|
+
let(:other) { Typhoeus::Request.new("base_url", options) }
|
77
|
+
|
78
|
+
context "when other base_url" do
|
79
|
+
it "returns false" do
|
80
|
+
expect(request).to_not eql other
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
context "when same base_url and other options" do
|
85
|
+
let(:other) { Typhoeus::Request.new(base_url, {}) }
|
86
|
+
|
87
|
+
it "returns false" do
|
88
|
+
expect(request).to_not eql other
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
context "when same base_url and options" do
|
94
|
+
context "when same order" do
|
95
|
+
let(:other) { Typhoeus::Request.new(base_url, options) }
|
96
|
+
|
97
|
+
it "returns true" do
|
98
|
+
expect(request).to eql other
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context "when different order" do
|
103
|
+
let(:other_options) { {:headers => { 'User-Agent' => "Fubar", }, :verbose => true } }
|
104
|
+
let(:other) { Typhoeus::Request.new(base_url, other_options)}
|
105
|
+
|
106
|
+
it "returns true" do
|
107
|
+
expect(request).to eql other
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
describe "#hash" do
|
115
|
+
context "when request.eql?(other)" do
|
116
|
+
let(:other) { Typhoeus::Request.new(base_url, options) }
|
117
|
+
|
118
|
+
it "has same hashes" do
|
119
|
+
expect(request.hash).to eq(other.hash)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
context "when not request.eql?(other)" do
|
124
|
+
let(:other) { Typhoeus::Request.new("base_url", {}) }
|
125
|
+
|
126
|
+
it "has different hashes" do
|
127
|
+
expect(request.hash).to_not eq(other.hash)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Typhoeus::Response::Header do
|
4
|
+
let(:raw) { nil }
|
5
|
+
let(:header) { Typhoeus::Response::Header.new(raw) }
|
6
|
+
|
7
|
+
describe ".new" do
|
8
|
+
context "when string" do
|
9
|
+
let(:raw) { 'Date: Fri, 29 Jun 2012 10:09:23 GMT' }
|
10
|
+
|
11
|
+
it "sets Date" do
|
12
|
+
expect(header['Date']).to eq('Fri, 29 Jun 2012 10:09:23 GMT')
|
13
|
+
end
|
14
|
+
|
15
|
+
it "provides case insensitive access" do
|
16
|
+
expect(header['DaTe']).to eq('Fri, 29 Jun 2012 10:09:23 GMT')
|
17
|
+
end
|
18
|
+
|
19
|
+
it "provides symbol access" do
|
20
|
+
expect(header[:date]).to eq('Fri, 29 Jun 2012 10:09:23 GMT')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when hash" do
|
25
|
+
let(:raw) { { 'Date' => 'Fri, 29 Jun 2012 10:09:23 GMT' } }
|
26
|
+
|
27
|
+
it "sets Date" do
|
28
|
+
expect(header['Date']).to eq(raw['Date'])
|
29
|
+
end
|
30
|
+
|
31
|
+
it "provides case insensitive access" do
|
32
|
+
expect(header['DaTe']).to eq(raw['Date'])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "#parse" do
|
38
|
+
context "when no header" do
|
39
|
+
it "returns nil" do
|
40
|
+
expect(header).to be_empty
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context "when header" do
|
45
|
+
let(:raw) do
|
46
|
+
'HTTP/1.1 200 OK
|
47
|
+
Set-Cookie: NID=61=LblqYgUOu; expires=Sat, 29-Dec-2012 10:09:23 GMT; path=/; domain=.google.de; HttpOnly
|
48
|
+
Date: Fri, 29 Jun 2012 10:09:23 GMT
|
49
|
+
Expires: -1
|
50
|
+
Cache-Control: private, max-age=0
|
51
|
+
Content-Type: text/html; charset=ISO-8859-1
|
52
|
+
Set-Cookie: PREF=ID=77e93yv0hPtejLou; expires=Sun, 29-Jun-2014 10:09:23 GMT; path=/; domain=.google.de
|
53
|
+
Set-Cookie: NID=61=LblqYgh5Ou; expires=Sat, 29-Dec-2012 10:09:23 GMT; path=/; domain=.google.de; HttpOnly
|
54
|
+
P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
|
55
|
+
Server: gws
|
56
|
+
X-XSS-Protection: 1; mode=block
|
57
|
+
X-Frame-Options: SAMEORIGIN
|
58
|
+
Transfer-Encoding: chunked'
|
59
|
+
end
|
60
|
+
|
61
|
+
it "sets raw" do
|
62
|
+
expect(header.send(:raw)).to eq(raw)
|
63
|
+
end
|
64
|
+
|
65
|
+
it "sets Set-Cookie" do
|
66
|
+
expect(header['set-cookie']).to have(3).items
|
67
|
+
end
|
68
|
+
|
69
|
+
it "provides case insensitive access" do
|
70
|
+
expect(header['Set-CooKie']).to have(3).items
|
71
|
+
end
|
72
|
+
|
73
|
+
[
|
74
|
+
'NID=61=LblqYgUOu; expires=Sat, 29-Dec-2012 10:09:23 GMT; path=/; domain=.google.de; HttpOnly',
|
75
|
+
'PREF=ID=77e93yv0hPtejLou; expires=Sun, 29-Jun-2014 10:09:23 GMT; path=/; domain=.google.de',
|
76
|
+
'NID=61=LblqYgh5Ou; expires=Sat, 29-Dec-2012 10:09:23 GMT; path=/; domain=.google.de; HttpOnly'
|
77
|
+
].each_with_index do |cookie, i|
|
78
|
+
it "sets Cookie##{i}" do
|
79
|
+
expect(header['set-cookie']).to include(cookie)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
{
|
84
|
+
'Date' => 'Fri, 29 Jun 2012 10:09:23 GMT', 'Expires' => '-1',
|
85
|
+
'Cache-Control' => 'private, max-age=0',
|
86
|
+
'Content-Type' => 'text/html; charset=ISO-8859-1',
|
87
|
+
'P3P' => 'CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."',
|
88
|
+
'Server' => 'gws', 'X-XSS-Protection' => '1; mode=block',
|
89
|
+
'X-Frame-Options' => 'SAMEORIGIN', 'Transfer-Encoding' => 'chunked'
|
90
|
+
}.each do |name, value|
|
91
|
+
it "sets #{name}" do
|
92
|
+
expect(header[name.downcase]).to eq(value)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,218 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Typhoeus::Response::Informations do
|
4
|
+
let(:options) { {} }
|
5
|
+
let(:response) { Typhoeus::Response.new(options) }
|
6
|
+
|
7
|
+
describe "#return_code" do
|
8
|
+
let(:options) { { :return_code => :ok } }
|
9
|
+
|
10
|
+
it "returns return_code from options" do
|
11
|
+
expect(response.return_code).to be(:ok)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#debug_info" do
|
16
|
+
let(:options) { { :debug_info => Ethon::Easy::DebugInfo.new } }
|
17
|
+
|
18
|
+
it "returns debug_info from options" do
|
19
|
+
expect(response.debug_info).to be_a(Ethon::Easy::DebugInfo)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
describe "#return_message" do
|
24
|
+
let(:options) { { :return_code => :couldnt_connect } }
|
25
|
+
|
26
|
+
it "returns a message" do
|
27
|
+
expect(response.return_message).to eq("Couldn't connect to server")
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
describe "#response_body" do
|
32
|
+
context "when response_body" do
|
33
|
+
let(:options) { { :response_body => "body" } }
|
34
|
+
|
35
|
+
it "returns response_body from options" do
|
36
|
+
expect(response.response_body).to eq("body")
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when body" do
|
41
|
+
let(:options) { { :body => "body" } }
|
42
|
+
|
43
|
+
it "returns body from options" do
|
44
|
+
expect(response.body).to eq("body")
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe "#response_headers" do
|
50
|
+
let(:options) { { :response_headers => "headers" } }
|
51
|
+
|
52
|
+
it "returns response_headers from options" do
|
53
|
+
expect(response.response_headers).to eq("headers")
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#response_code" do
|
58
|
+
context "when response_code" do
|
59
|
+
let(:options) { { :response_code => "200" } }
|
60
|
+
|
61
|
+
it "returns response_code from options" do
|
62
|
+
expect(response.response_code).to eq(200)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context "when code" do
|
67
|
+
let(:options) { { :code => "200" } }
|
68
|
+
|
69
|
+
it "returns code from options" do
|
70
|
+
expect(response.code).to eq(200)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
75
|
+
describe "#httpauth_avail" do
|
76
|
+
let(:options) { { :httpauth_avail => "code" } }
|
77
|
+
|
78
|
+
it "returns httpauth_avail from options" do
|
79
|
+
expect(response.httpauth_avail).to eq("code")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe "#total_time" do
|
84
|
+
let(:options) { { :total_time => 1 } }
|
85
|
+
|
86
|
+
it "returns total_time from options" do
|
87
|
+
expect(response.total_time).to eq(1)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe "#starttransfer_time" do
|
92
|
+
let(:options) { { :starttransfer_time => 1 } }
|
93
|
+
|
94
|
+
it "returns starttransfer_time from options" do
|
95
|
+
expect(response.starttransfer_time).to eq(1)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe "#appconnect_time" do
|
100
|
+
let(:options) { { :appconnect_time => 1 } }
|
101
|
+
|
102
|
+
it "returns appconnect_time from options" do
|
103
|
+
expect(response.appconnect_time).to eq(1)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
describe "#pretransfer_time" do
|
108
|
+
let(:options) { { :pretransfer_time => 1 } }
|
109
|
+
|
110
|
+
it "returns pretransfer_time from options" do
|
111
|
+
expect(response.pretransfer_time).to eq(1)
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
describe "#connect_time" do
|
116
|
+
let(:options) { { :connect_time => 1 } }
|
117
|
+
|
118
|
+
it "returns connect_time from options" do
|
119
|
+
expect(response.connect_time).to eq(1)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
describe "#namelookup_time" do
|
124
|
+
let(:options) { { :namelookup_time => 1 } }
|
125
|
+
|
126
|
+
it "returns namelookup_time from options" do
|
127
|
+
expect(response.namelookup_time).to eq(1)
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
describe "#effective_url" do
|
132
|
+
let(:options) { { :effective_url => "http://www.example.com" } }
|
133
|
+
|
134
|
+
it "returns effective_url from options" do
|
135
|
+
expect(response.effective_url).to eq("http://www.example.com")
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
139
|
+
describe "#primary_ip" do
|
140
|
+
let(:options) { { :primary_ip => "127.0.0.1" } }
|
141
|
+
|
142
|
+
it "returns primary_ip from options" do
|
143
|
+
expect(response.primary_ip).to eq("127.0.0.1")
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
describe "#redirect_count" do
|
148
|
+
let(:options) { { :redirect_count => 2 } }
|
149
|
+
|
150
|
+
it "returns redirect_count from options" do
|
151
|
+
expect(response.redirect_count).to eq(2)
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
describe "#headers" do
|
156
|
+
context "when no headers" do
|
157
|
+
it "returns nil" do
|
158
|
+
expect(response.headers).to be_nil
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context "when headers" do
|
163
|
+
let(:options) { {:response_headers => "Expire: -1\nServer: gws"} }
|
164
|
+
|
165
|
+
it "returns nonempty headers" do
|
166
|
+
expect(response.headers).to_not be_empty
|
167
|
+
end
|
168
|
+
|
169
|
+
it "has Expire" do
|
170
|
+
expect(response.headers['expire']).to eq('-1')
|
171
|
+
end
|
172
|
+
|
173
|
+
it "has Server" do
|
174
|
+
expect(response.headers['server']).to eq('gws')
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context "when multiple headers" do
|
179
|
+
let(:options) { {:response_headers => "Server: A\r\n\r\nServer: B"} }
|
180
|
+
|
181
|
+
it "returns the last" do
|
182
|
+
expect(response.headers['server']).to eq("B")
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
186
|
+
context "when requesting" do
|
187
|
+
let(:response) { Typhoeus.get("localhost:3001") }
|
188
|
+
|
189
|
+
it "returns headers" do
|
190
|
+
expect(response.headers).to_not be_empty
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
describe "#redirections" do
|
196
|
+
context "when no response_headers" do
|
197
|
+
it "returns empty array" do
|
198
|
+
expect(response.redirections).to be_empty
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
context "when headers" do
|
203
|
+
let(:options) { {:response_headers => "Expire: -1\nServer: gws"} }
|
204
|
+
|
205
|
+
it "returns empty array" do
|
206
|
+
expect(response.redirections).to be_empty
|
207
|
+
end
|
208
|
+
end
|
209
|
+
|
210
|
+
context "when multiple headers" do
|
211
|
+
let(:options) { {:response_headers => "Server: A\r\n\r\nServer: B"} }
|
212
|
+
|
213
|
+
it "returns response from all but last headers" do
|
214
|
+
expect(response.redirections).to have(1).item
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|