typhoeus 1.0.1 → 1.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +12 -7
- data/CHANGELOG.md +34 -2
- data/CONTRIBUTING.md +4 -0
- data/Gemfile +14 -3
- data/LICENSE +1 -1
- data/README.md +67 -42
- data/lib/typhoeus/adapters/faraday.rb +30 -9
- data/lib/typhoeus/cache/dalli.rb +28 -0
- data/lib/typhoeus/cache/rails.rb +28 -0
- data/lib/typhoeus/cache/redis.rb +35 -0
- data/lib/typhoeus/config.rb +8 -1
- data/lib/typhoeus/easy_factory.rb +8 -3
- data/lib/typhoeus/hydra/cacheable.rb +1 -1
- data/lib/typhoeus/pool.rb +2 -0
- data/lib/typhoeus/request/actions.rb +7 -7
- data/lib/typhoeus/request/cacheable.rb +14 -3
- data/lib/typhoeus/request/callbacks.rb +21 -3
- data/lib/typhoeus/request/marshal.rb +2 -2
- data/lib/typhoeus/request/streamable.rb +1 -1
- data/lib/typhoeus/request.rb +2 -0
- data/lib/typhoeus/response/header.rb +13 -5
- data/lib/typhoeus/response/informations.rb +7 -3
- data/lib/typhoeus/response/status.rb +22 -2
- data/lib/typhoeus/response.rb +1 -1
- data/lib/typhoeus/version.rb +1 -1
- data/lib/typhoeus.rb +19 -3
- data/spec/support/server.rb +8 -0
- data/spec/typhoeus/adapters/faraday_spec.rb +237 -191
- data/spec/typhoeus/cache/dalli_spec.rb +41 -0
- data/spec/typhoeus/cache/redis_spec.rb +41 -0
- data/spec/typhoeus/config_spec.rb +1 -1
- data/spec/typhoeus/easy_factory_spec.rb +6 -0
- data/spec/typhoeus/hydra/before_spec.rb +9 -8
- data/spec/typhoeus/hydra/cacheable_spec.rb +31 -1
- data/spec/typhoeus/hydra/runnable_spec.rb +4 -3
- data/spec/typhoeus/pool_spec.rb +43 -2
- data/spec/typhoeus/request/before_spec.rb +9 -8
- data/spec/typhoeus/request/cacheable_spec.rb +24 -0
- data/spec/typhoeus/request/callbacks_spec.rb +2 -2
- data/spec/typhoeus/request/marshal_spec.rb +1 -1
- data/spec/typhoeus/request_spec.rb +21 -3
- data/spec/typhoeus/response/header_spec.rb +51 -1
- data/spec/typhoeus/response/informations_spec.rb +12 -1
- data/spec/typhoeus/response/status_spec.rb +54 -0
- data/typhoeus.gemspec +1 -1
- metadata +12 -5
@@ -3,13 +3,14 @@ require 'spec_helper'
|
|
3
3
|
describe Typhoeus::Hydra::Before do
|
4
4
|
let(:request) { Typhoeus::Request.new("") }
|
5
5
|
let(:hydra) { Typhoeus::Hydra.new }
|
6
|
+
let(:receive_counter) { double :mark => :twain }
|
6
7
|
|
7
8
|
describe "#add" do
|
8
9
|
context "when before" do
|
9
10
|
context "when one" do
|
10
11
|
it "executes" do
|
11
|
-
Typhoeus.before { |r|
|
12
|
-
expect(
|
12
|
+
Typhoeus.before { |r| receive_counter.mark }
|
13
|
+
expect(receive_counter).to receive(:mark)
|
13
14
|
hydra.add(request)
|
14
15
|
end
|
15
16
|
|
@@ -54,7 +55,7 @@ describe Typhoeus::Hydra::Before do
|
|
54
55
|
|
55
56
|
context "when multi" do
|
56
57
|
context "when all true" do
|
57
|
-
before { 3.times { Typhoeus.before { |r|
|
58
|
+
before { 3.times { Typhoeus.before { |r| receive_counter.mark } } }
|
58
59
|
|
59
60
|
it "calls super" do
|
60
61
|
expect(Typhoeus::Expectation).to receive(:response_for)
|
@@ -62,16 +63,16 @@ describe Typhoeus::Hydra::Before do
|
|
62
63
|
end
|
63
64
|
|
64
65
|
it "executes all" do
|
65
|
-
expect(
|
66
|
+
expect(receive_counter).to receive(:mark).exactly(3).times
|
66
67
|
hydra.add(request)
|
67
68
|
end
|
68
69
|
end
|
69
70
|
|
70
71
|
context "when middle false" do
|
71
72
|
before do
|
72
|
-
Typhoeus.before { |r|
|
73
|
-
Typhoeus.before { |r|
|
74
|
-
Typhoeus.before { |r|
|
73
|
+
Typhoeus.before { |r| receive_counter.mark }
|
74
|
+
Typhoeus.before { |r| receive_counter.mark; nil }
|
75
|
+
Typhoeus.before { |r| receive_counter.mark }
|
75
76
|
end
|
76
77
|
|
77
78
|
it "doesn't call super" do
|
@@ -80,7 +81,7 @@ describe Typhoeus::Hydra::Before do
|
|
80
81
|
end
|
81
82
|
|
82
83
|
it "executes only two" do
|
83
|
-
expect(
|
84
|
+
expect(receive_counter).to receive(:mark).exactly(2).times
|
84
85
|
hydra.add(request)
|
85
86
|
end
|
86
87
|
end
|
@@ -4,6 +4,7 @@ describe Typhoeus::Hydra::Cacheable do
|
|
4
4
|
let(:base_url) { "localhost:3001" }
|
5
5
|
let(:hydra) { Typhoeus::Hydra.new() }
|
6
6
|
let(:request) { Typhoeus::Request.new(base_url, {:method => :get}) }
|
7
|
+
let(:response) { Typhoeus::Response.new }
|
7
8
|
let(:cache) { MemoryCache.new }
|
8
9
|
|
9
10
|
describe "add" do
|
@@ -24,7 +25,6 @@ describe Typhoeus::Hydra::Cacheable do
|
|
24
25
|
end
|
25
26
|
|
26
27
|
context "when request in memory" do
|
27
|
-
let(:response) { Typhoeus::Response.new }
|
28
28
|
before { cache.memory[request] = response }
|
29
29
|
|
30
30
|
it "returns response with cached status" do
|
@@ -53,6 +53,36 @@ describe Typhoeus::Hydra::Cacheable do
|
|
53
53
|
end
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
context "when cache is specified on a request" do
|
58
|
+
before { Typhoeus::Config.cache = false }
|
59
|
+
|
60
|
+
context "when cache is false" do
|
61
|
+
let(:non_cached_request) { Typhoeus::Request.new(base_url, {:method => :get, :cache => false}) }
|
62
|
+
|
63
|
+
it "initiates an HTTP call" do
|
64
|
+
expect(Typhoeus::EasyFactory).to receive(:new).with(non_cached_request, hydra).and_call_original
|
65
|
+
|
66
|
+
hydra.add(non_cached_request)
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
context "when cache is defined" do
|
71
|
+
let(:cached_request) { Typhoeus::Request.new(base_url, {:method => :get, :cache => cache}) }
|
72
|
+
|
73
|
+
before { cache.memory[cached_request] = response }
|
74
|
+
|
75
|
+
it "uses the cache instead of making a new request" do
|
76
|
+
expect(Typhoeus::EasyFactory).not_to receive(:new)
|
77
|
+
|
78
|
+
hydra.add(cached_request)
|
79
|
+
|
80
|
+
expect(cached_request.response).to be_cached
|
81
|
+
expect(cached_request.response).to eq(response)
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
56
86
|
end
|
57
87
|
end
|
58
88
|
end
|
@@ -4,6 +4,7 @@ describe Typhoeus::Hydra::Runnable do
|
|
4
4
|
let(:base_url) { "localhost:3001" }
|
5
5
|
let(:options) { {} }
|
6
6
|
let(:hydra) { Typhoeus::Hydra.new(options) }
|
7
|
+
let(:receive_counter) { double :mark => :twain }
|
7
8
|
|
8
9
|
describe "#run" do
|
9
10
|
let(:requests) { [] }
|
@@ -107,7 +108,7 @@ describe Typhoeus::Hydra::Runnable do
|
|
107
108
|
let(:second) { Typhoeus::Request.new("localhost:3001/second") }
|
108
109
|
let(:requests) { [first] }
|
109
110
|
|
110
|
-
before { Typhoeus.on_complete { |r|
|
111
|
+
before { Typhoeus.on_complete { |r| receive_counter.mark } }
|
111
112
|
after { Typhoeus.on_complete.clear; Typhoeus.before.clear }
|
112
113
|
|
113
114
|
context "when real request" do
|
@@ -115,7 +116,7 @@ describe Typhoeus::Hydra::Runnable do
|
|
115
116
|
let(:options) { {} }
|
116
117
|
|
117
118
|
it "calls on_complete callback once for every response" do
|
118
|
-
expect(
|
119
|
+
expect(receive_counter).to receive(:mark).exactly(2).times
|
119
120
|
hydra.run
|
120
121
|
end
|
121
122
|
end
|
@@ -126,7 +127,7 @@ describe Typhoeus::Hydra::Runnable do
|
|
126
127
|
before { Typhoeus.before{ |request| request.finish(Typhoeus::Response.new) } }
|
127
128
|
|
128
129
|
it "simulates real multi run and adds and finishes both requests" do
|
129
|
-
expect(
|
130
|
+
expect(receive_counter).to receive(:mark).exactly(2).times
|
130
131
|
hydra.run
|
131
132
|
end
|
132
133
|
end
|
data/spec/typhoeus/pool_spec.rb
CHANGED
@@ -16,6 +16,45 @@ describe Typhoeus::Pool do
|
|
16
16
|
Typhoeus::Pool.release(easy)
|
17
17
|
end
|
18
18
|
|
19
|
+
it "flush cookies to disk" do
|
20
|
+
expect(easy).to receive(:cookielist=).with('flush')
|
21
|
+
expect(easy).to receive(:reset)
|
22
|
+
expect(easy).to receive(:cookielist=).with('all')
|
23
|
+
Typhoeus::Pool.release(easy)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "writes cookies to disk" do
|
27
|
+
tempfile1 = Tempfile.new('cookies')
|
28
|
+
tempfile2 = Tempfile.new('cookies')
|
29
|
+
|
30
|
+
easy.cookiejar = tempfile1.path
|
31
|
+
easy.url = "localhost:3001/cookies-test"
|
32
|
+
easy.perform
|
33
|
+
|
34
|
+
Typhoeus::Pool.release(easy)
|
35
|
+
|
36
|
+
expect(File.zero?(tempfile1.path)).to be(false)
|
37
|
+
expect(File.read(tempfile1.path)).to match(/\s+foo\s+bar$/)
|
38
|
+
expect(File.read(tempfile1.path)).to match(/\s+bar\s+foo$/)
|
39
|
+
|
40
|
+
# do it again - and check if tempfile1 wasn't change
|
41
|
+
easy.cookiejar = tempfile2.path
|
42
|
+
easy.url = "localhost:3001/cookies-test2"
|
43
|
+
easy.perform
|
44
|
+
|
45
|
+
Typhoeus::Pool.release(easy)
|
46
|
+
|
47
|
+
# tempfile 1
|
48
|
+
expect(File.zero?(tempfile1.path)).to be(false)
|
49
|
+
expect(File.read(tempfile1.path)).to match(/\s+foo\s+bar$/)
|
50
|
+
expect(File.read(tempfile1.path)).to match(/\s+bar\s+foo$/)
|
51
|
+
|
52
|
+
# tempfile2
|
53
|
+
expect(File.zero?(tempfile2.path)).to be(false)
|
54
|
+
expect(File.read(tempfile2.path)).to match(/\s+foo2\s+bar$/)
|
55
|
+
expect(File.read(tempfile2.path)).to match(/\s+bar2\s+foo$/)
|
56
|
+
end
|
57
|
+
|
19
58
|
it "puts easy back into pool" do
|
20
59
|
Typhoeus::Pool.release(easy)
|
21
60
|
expect(Typhoeus::Pool.send(:easies)).to include(easy)
|
@@ -49,12 +88,14 @@ describe Typhoeus::Pool do
|
|
49
88
|
|
50
89
|
context "when threaded access" do
|
51
90
|
it "creates correct number of easies" do
|
52
|
-
|
91
|
+
queue = Queue.new
|
53
92
|
(0..9).map do |n|
|
54
93
|
Thread.new do
|
55
|
-
|
94
|
+
queue.enq(Typhoeus::Pool.get)
|
56
95
|
end
|
57
96
|
end.map(&:join)
|
97
|
+
|
98
|
+
array = Array.new(queue.size) { queue.pop }
|
58
99
|
expect(array.uniq.size).to eq(10)
|
59
100
|
end
|
60
101
|
end
|
@@ -2,13 +2,14 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Typhoeus::Request::Before do
|
4
4
|
let(:request) { Typhoeus::Request.new("") }
|
5
|
+
let(:receive_counter) { double :mark => :twain }
|
5
6
|
|
6
7
|
describe "#queue" do
|
7
8
|
context "when before" do
|
8
9
|
context "when one" do
|
9
10
|
it "executes" do
|
10
|
-
Typhoeus.before { |r|
|
11
|
-
expect(
|
11
|
+
Typhoeus.before { |r| receive_counter.mark }
|
12
|
+
expect(receive_counter).to receive(:mark)
|
12
13
|
request.run
|
13
14
|
end
|
14
15
|
|
@@ -49,7 +50,7 @@ describe Typhoeus::Request::Before do
|
|
49
50
|
|
50
51
|
context "when multi" do
|
51
52
|
context "when all true" do
|
52
|
-
before { 3.times { Typhoeus.before { |r|
|
53
|
+
before { 3.times { Typhoeus.before { |r| receive_counter.mark } } }
|
53
54
|
|
54
55
|
it "calls super" do
|
55
56
|
expect(Typhoeus::Expectation).to receive(:response_for)
|
@@ -57,16 +58,16 @@ describe Typhoeus::Request::Before do
|
|
57
58
|
end
|
58
59
|
|
59
60
|
it "executes all" do
|
60
|
-
expect(
|
61
|
+
expect(receive_counter).to receive(:mark).exactly(3)
|
61
62
|
request.run
|
62
63
|
end
|
63
64
|
end
|
64
65
|
|
65
66
|
context "when middle false" do
|
66
67
|
before do
|
67
|
-
Typhoeus.before { |r|
|
68
|
-
Typhoeus.before { |r|
|
69
|
-
Typhoeus.before { |r|
|
68
|
+
Typhoeus.before { |r| receive_counter.mark }
|
69
|
+
Typhoeus.before { |r| receive_counter.mark; nil }
|
70
|
+
Typhoeus.before { |r| receive_counter.mark }
|
70
71
|
end
|
71
72
|
|
72
73
|
it "doesn't call super" do
|
@@ -75,7 +76,7 @@ describe Typhoeus::Request::Before do
|
|
75
76
|
end
|
76
77
|
|
77
78
|
it "executes only two" do
|
78
|
-
expect(
|
79
|
+
expect(receive_counter).to receive(:mark).exactly(2).times
|
79
80
|
request.run
|
80
81
|
end
|
81
82
|
end
|
@@ -55,6 +55,30 @@ describe Typhoeus::Request::Cacheable do
|
|
55
55
|
request.run
|
56
56
|
end
|
57
57
|
end
|
58
|
+
|
59
|
+
context "when cache is specified on a request" do
|
60
|
+
before { Typhoeus::Config.cache = false }
|
61
|
+
|
62
|
+
context "when cache is false" do
|
63
|
+
let(:options) { { :cache => false } }
|
64
|
+
|
65
|
+
it "finishes request" do
|
66
|
+
expect(request.response).to_not be(response)
|
67
|
+
request.run
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when cache is defined" do
|
72
|
+
let(:options) { { :cache => cache } }
|
73
|
+
|
74
|
+
before { cache.memory[request] = response }
|
75
|
+
|
76
|
+
it "finishes request" do
|
77
|
+
expect(request).to receive(:finish).with(response)
|
78
|
+
request.run
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
58
82
|
end
|
59
83
|
end
|
60
84
|
|
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe Typhoeus::Request::Callbacks do
|
4
4
|
let(:request) { Typhoeus::Request.new("fubar") }
|
5
5
|
|
6
|
-
[:on_complete, :on_success, :on_failure].each do |callback|
|
6
|
+
[:on_complete, :on_success, :on_failure, :on_progress].each do |callback|
|
7
7
|
describe "##{callback}" do
|
8
8
|
it "responds" do
|
9
9
|
expect(request).to respond_to(callback)
|
@@ -33,7 +33,7 @@ describe Typhoeus::Request::Callbacks do
|
|
33
33
|
end
|
34
34
|
|
35
35
|
describe "#execute_callbacks" do
|
36
|
-
[:on_complete, :on_success, :on_failure].each do |callback|
|
36
|
+
[:on_complete, :on_success, :on_failure, :on_progress].each do |callback|
|
37
37
|
context "when #{callback}" do
|
38
38
|
context "when local callback" do
|
39
39
|
before do
|
@@ -5,7 +5,7 @@ describe Typhoeus::Request::Marshal do
|
|
5
5
|
let(:request) { Typhoeus::Request.new(base_url) }
|
6
6
|
|
7
7
|
describe "#marshal_dump" do
|
8
|
-
%w(on_complete on_success on_failure).each do |name|
|
8
|
+
%w(on_complete on_success on_failure on_progress).each do |name|
|
9
9
|
context "when #{name} handler" do
|
10
10
|
before { request.instance_variable_set("@#{name}", Proc.new{}) }
|
11
11
|
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Typhoeus::Request do
|
4
4
|
let(:base_url) { "localhost:3001" }
|
5
|
-
let(:options) { {:verbose => true, :headers => { 'User-Agent' => "Fubar" }, :maxredirs => 50} }
|
5
|
+
let(:options) { {:verbose => true, :headers => { 'User-Agent' => "Fubar", 'Expect' => "" }, :maxredirs => 50} }
|
6
6
|
let(:request) { Typhoeus::Request.new(base_url, options) }
|
7
7
|
|
8
8
|
describe ".url" do
|
@@ -110,6 +110,23 @@ describe Typhoeus::Request do
|
|
110
110
|
end
|
111
111
|
end
|
112
112
|
end
|
113
|
+
|
114
|
+
context "when Config.proxy set" do
|
115
|
+
before { Typhoeus.configure { |config| config.proxy = "http://proxy.internal" } }
|
116
|
+
after { Typhoeus.configure { |config| config.proxy = nil } }
|
117
|
+
|
118
|
+
it "respects" do
|
119
|
+
expect(request.options[:proxy]).to eq("http://proxy.internal")
|
120
|
+
end
|
121
|
+
|
122
|
+
context "when option proxy set" do
|
123
|
+
let(:options) { {:proxy => nil} }
|
124
|
+
|
125
|
+
it "does not override" do
|
126
|
+
expect(request.options[:proxy]).to be_nil
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
113
130
|
end
|
114
131
|
|
115
132
|
describe "#eql?" do
|
@@ -150,7 +167,7 @@ describe Typhoeus::Request do
|
|
150
167
|
|
151
168
|
context "when different order" do
|
152
169
|
let(:other_options) {
|
153
|
-
{:headers => { 'User-Agent' => "Fubar" }, :verbose => true }
|
170
|
+
{:headers => { 'User-Agent' => "Fubar", 'Expect' => ""}, :verbose => true }
|
154
171
|
}
|
155
172
|
let(:other) { Typhoeus::Request.new(base_url, other_options)}
|
156
173
|
|
@@ -166,7 +183,7 @@ describe Typhoeus::Request do
|
|
166
183
|
context "when request.eql?(other)" do
|
167
184
|
context "when different order" do
|
168
185
|
let(:other_options) {
|
169
|
-
{:headers => { 'User-Agent' => "Fubar" }, :verbose => true }
|
186
|
+
{:headers => { 'User-Agent' => "Fubar", 'Expect' => "" }, :verbose => true }
|
170
187
|
}
|
171
188
|
let(:other) { Typhoeus::Request.new(base_url, other_options)}
|
172
189
|
|
@@ -211,4 +228,5 @@ describe Typhoeus::Request do
|
|
211
228
|
expect(request.encoded_body).to eq("a=1")
|
212
229
|
end
|
213
230
|
end
|
231
|
+
|
214
232
|
end
|
@@ -55,7 +55,7 @@ describe Typhoeus::Response::Header do
|
|
55
55
|
Server: gws
|
56
56
|
X-XSS-Protection: 1; mode=block
|
57
57
|
X-Frame-Options: SAMEORIGIN
|
58
|
-
Transfer-Encoding: chunked'
|
58
|
+
Transfer-Encoding: chunked'.gsub(/^\s{8}/, '')
|
59
59
|
end
|
60
60
|
|
61
61
|
it "sets raw" do
|
@@ -92,6 +92,56 @@ describe Typhoeus::Response::Header do
|
|
92
92
|
expect(header[name.downcase]).to eq(value)
|
93
93
|
end
|
94
94
|
end
|
95
|
+
|
96
|
+
context 'includes a multi-line header' do
|
97
|
+
let(:raw) do
|
98
|
+
'HTTP/1.1 200 OK
|
99
|
+
Date: Fri, 29 Jun 2012 10:09:23 GMT
|
100
|
+
Content-Security-Policy: default-src "self";
|
101
|
+
img-src * data: "self";
|
102
|
+
upgrade-insecure-requests;'.gsub(/^\s{10}/, '')
|
103
|
+
end
|
104
|
+
|
105
|
+
it "joins header parts" do
|
106
|
+
expect(header).to eq({
|
107
|
+
'Date' => 'Fri, 29 Jun 2012 10:09:23 GMT',
|
108
|
+
'Content-Security-Policy' => 'default-src "self"; img-src * data: "self"; upgrade-insecure-requests;'
|
109
|
+
})
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
context 'includes line with only whitespace' do
|
114
|
+
let(:raw) do
|
115
|
+
'HTTP/1.1 200 OK
|
116
|
+
Date: Fri, 29 Jun 2012 10:09:23 GMT
|
117
|
+
|
118
|
+
'.gsub(/^\s{10}/, '')
|
119
|
+
end
|
120
|
+
|
121
|
+
it 'ignores it' do
|
122
|
+
expect(header).to eq({ 'Date' => 'Fri, 29 Jun 2012 10:09:23 GMT' })
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
context 'with broken headers' do
|
127
|
+
let(:raw) do
|
128
|
+
'HTTP/1.1 200 OK
|
129
|
+
Date:
|
130
|
+
Content-Type
|
131
|
+
'.gsub(/^\s{10}/, '')
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'returns empty string for invalid headers' do
|
135
|
+
expect(header.to_hash).to include({ 'Date' => '', 'Content-Type' => '' })
|
136
|
+
end
|
137
|
+
end
|
95
138
|
end
|
96
139
|
end
|
140
|
+
|
141
|
+
it "can be Marshal'd" do
|
142
|
+
header = Typhoeus::Response::Header.new("Foo: Bar")
|
143
|
+
expect {
|
144
|
+
Marshal.dump(header)
|
145
|
+
}.not_to raise_error
|
146
|
+
end
|
97
147
|
end
|
@@ -74,6 +74,17 @@ describe Typhoeus::Response::Informations do
|
|
74
74
|
expect(response.response_headers).to include("\r\n")
|
75
75
|
end
|
76
76
|
end
|
77
|
+
|
78
|
+
context "when multiple values for a header" do
|
79
|
+
let(:options) { { :mock => true, :headers => {"Length" => 1, "Content-Type" => "text/plain", "set-cookie" => ["cookieone=one","cookietwo=two"] } } }
|
80
|
+
|
81
|
+
it "constructs response_headers" do
|
82
|
+
expect(response.response_headers).to include("Length: 1")
|
83
|
+
expect(response.response_headers).to include("Content-Type: text/plain")
|
84
|
+
expect(response.response_headers).to include("set-cookie: cookieone=one,cookietwo=two")
|
85
|
+
expect(response.response_headers).to include("\r\n")
|
86
|
+
end
|
87
|
+
end
|
77
88
|
end
|
78
89
|
end
|
79
90
|
end
|
@@ -232,7 +243,7 @@ describe Typhoeus::Response::Informations do
|
|
232
243
|
end
|
233
244
|
|
234
245
|
it "returns headers" do
|
235
|
-
expect(response.headers).to include("Length" => "1")
|
246
|
+
expect(response.headers.to_hash).to include("Length" => "1")
|
236
247
|
end
|
237
248
|
end
|
238
249
|
end
|
@@ -128,6 +128,60 @@ describe Typhoeus::Response::Status do
|
|
128
128
|
end
|
129
129
|
end
|
130
130
|
|
131
|
+
describe "#failure?" do
|
132
|
+
context "when response code between 300-526 and 100-300" do
|
133
|
+
let(:options) { {:return_code => return_code, :response_code => 300} }
|
134
|
+
|
135
|
+
context "when mock" do
|
136
|
+
before { response.mock = true }
|
137
|
+
|
138
|
+
context "when return_code :internal_server_error" do
|
139
|
+
let(:return_code) { :internal_server_error }
|
140
|
+
|
141
|
+
it "returns true" do
|
142
|
+
expect(response.failure?).to be_truthy
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
context "when return_code nil" do
|
147
|
+
let(:return_code) { nil }
|
148
|
+
|
149
|
+
it "returns true" do
|
150
|
+
expect(response.failure?).to be_truthy
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context "when no mock" do
|
156
|
+
before { response.mock = nil }
|
157
|
+
|
158
|
+
context "when return_code :internal_server_error" do
|
159
|
+
let(:return_code) { :internal_server_error }
|
160
|
+
|
161
|
+
it "returns true" do
|
162
|
+
expect(response.failure?).to be_truthy
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
context "when return_code nil" do
|
167
|
+
let(:return_code) { nil }
|
168
|
+
|
169
|
+
it "returns false" do
|
170
|
+
expect(response.failure?).to be_falsey
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context "when response code is not 300-526" do
|
177
|
+
let(:options) { {:return_code => :ok, :response_code => 200} }
|
178
|
+
|
179
|
+
it "returns false" do
|
180
|
+
expect(response.failure?).to be_falsey
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
131
185
|
describe "#modified?" do
|
132
186
|
context "when response code 304" do
|
133
187
|
let(:options) { {:return_code => :ok, :response_code => 304} }
|
data/typhoeus.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |s|
|
|
17
17
|
s.required_rubygems_version = ">= 1.3.6"
|
18
18
|
s.license = 'MIT'
|
19
19
|
|
20
|
-
s.add_dependency('ethon', [">= 0.
|
20
|
+
s.add_dependency('ethon', [">= 0.9.0"])
|
21
21
|
|
22
22
|
s.files = `git ls-files`.split("\n")
|
23
23
|
s.test_files = `git ls-files -- spec/*`.split("\n")
|
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: 1.0
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Balatero
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-05-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ethon
|
@@ -18,14 +18,14 @@ dependencies:
|
|
18
18
|
requirements:
|
19
19
|
- - ">="
|
20
20
|
- !ruby/object:Gem::Version
|
21
|
-
version: 0.
|
21
|
+
version: 0.9.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
requirements:
|
26
26
|
- - ">="
|
27
27
|
- !ruby/object:Gem::Version
|
28
|
-
version: 0.
|
28
|
+
version: 0.9.0
|
29
29
|
description: Like a modern code version of the mythical beast with 100 serpent heads,
|
30
30
|
Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic.
|
31
31
|
email:
|
@@ -50,6 +50,9 @@ files:
|
|
50
50
|
- lib/rack/typhoeus/middleware/params_decoder/helper.rb
|
51
51
|
- lib/typhoeus.rb
|
52
52
|
- lib/typhoeus/adapters/faraday.rb
|
53
|
+
- lib/typhoeus/cache/dalli.rb
|
54
|
+
- lib/typhoeus/cache/rails.rb
|
55
|
+
- lib/typhoeus/cache/redis.rb
|
53
56
|
- lib/typhoeus/config.rb
|
54
57
|
- lib/typhoeus/easy_factory.rb
|
55
58
|
- lib/typhoeus/errors.rb
|
@@ -94,6 +97,8 @@ files:
|
|
94
97
|
- spec/support/memory_cache.rb
|
95
98
|
- spec/support/server.rb
|
96
99
|
- spec/typhoeus/adapters/faraday_spec.rb
|
100
|
+
- spec/typhoeus/cache/dalli_spec.rb
|
101
|
+
- spec/typhoeus/cache/redis_spec.rb
|
97
102
|
- spec/typhoeus/config_spec.rb
|
98
103
|
- spec/typhoeus/easy_factory_spec.rb
|
99
104
|
- spec/typhoeus/errors/no_stub_spec.rb
|
@@ -145,7 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
145
150
|
version: 1.3.6
|
146
151
|
requirements: []
|
147
152
|
rubyforge_project:
|
148
|
-
rubygems_version: 2.2.
|
153
|
+
rubygems_version: 2.5.2.3
|
149
154
|
signing_key:
|
150
155
|
specification_version: 4
|
151
156
|
summary: Parallel HTTP library on top of libcurl multi.
|
@@ -157,6 +162,8 @@ test_files:
|
|
157
162
|
- spec/support/memory_cache.rb
|
158
163
|
- spec/support/server.rb
|
159
164
|
- spec/typhoeus/adapters/faraday_spec.rb
|
165
|
+
- spec/typhoeus/cache/dalli_spec.rb
|
166
|
+
- spec/typhoeus/cache/redis_spec.rb
|
160
167
|
- spec/typhoeus/config_spec.rb
|
161
168
|
- spec/typhoeus/easy_factory_spec.rb
|
162
169
|
- spec/typhoeus/errors/no_stub_spec.rb
|