typhoeus 0.6.8 → 0.6.9
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/.travis.yml +1 -1
- data/CHANGELOG.md +2 -1
- data/README.md +9 -0
- data/lib/typhoeus/easy_factory.rb +2 -2
- data/lib/typhoeus/hydra.rb +1 -1
- data/lib/typhoeus/hydra/queueable.rb +16 -0
- data/lib/typhoeus/hydra/runnable.rb +1 -7
- data/lib/typhoeus/request/stubbable.rb +2 -2
- data/lib/typhoeus/response/informations.rb +4 -0
- data/lib/typhoeus/version.rb +1 -1
- data/spec/rack/typhoeus/middleware/params_decoder/helper_spec.rb +4 -4
- data/spec/rack/typhoeus/middleware/params_decoder_spec.rb +2 -2
- data/spec/typhoeus/adapters/faraday_spec.rb +6 -6
- data/spec/typhoeus/easy_factory_spec.rb +8 -8
- data/spec/typhoeus/expectation_spec.rb +18 -18
- data/spec/typhoeus/hydra/addable_spec.rb +6 -6
- data/spec/typhoeus/hydra/before_spec.rb +9 -9
- data/spec/typhoeus/hydra/cacheable_spec.rb +6 -6
- data/spec/typhoeus/hydra/memoizable_spec.rb +5 -5
- data/spec/typhoeus/hydra/queueable_spec.rb +49 -0
- data/spec/typhoeus/hydra/runnable_spec.rb +11 -30
- data/spec/typhoeus/hydra/stubbable_spec.rb +1 -1
- data/spec/typhoeus/hydra_spec.rb +1 -1
- data/spec/typhoeus/pool_spec.rb +4 -4
- data/spec/typhoeus/request/before_spec.rb +9 -9
- data/spec/typhoeus/request/block_connection_spec.rb +5 -5
- data/spec/typhoeus/request/cacheable_spec.rb +4 -4
- data/spec/typhoeus/request/callbacks_spec.rb +3 -3
- data/spec/typhoeus/request/operations_spec.rb +7 -7
- data/spec/typhoeus/request/stubbable_spec.rb +1 -1
- data/spec/typhoeus/request_spec.rb +3 -3
- data/spec/typhoeus/response/header_spec.rb +2 -2
- data/spec/typhoeus/response/informations_spec.rb +9 -1
- data/spec/typhoeus/response/status_spec.rb +10 -10
- data/spec/typhoeus/response_spec.rb +4 -4
- data/spec/typhoeus_spec.rb +4 -4
- data/typhoeus.gemspec +1 -1
- metadata +7 -14
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
YmYzNGMzZmI1NzgwZjM4MjE3Mjc3OTkxMzkzZDQ4NWI1MmViZGQ4OQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YTVlMWVhYjBjYzczYTgyYWUzN2E3NDNiM2Y0ZTc2YjViNDZmMzUyYw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
M2MwNzI3MmM3NmE0OGU3OGQ3OTY2OThmOGQ4ZDFiNzU2ZDU4NGYyYTFhM2Y1
|
10
|
+
ZGZiNTUwNjFhYjlmMTJjM2QwY2ZjNjlkZDkwOTRjYzIxOWNkMzA0YzZhMWY4
|
11
|
+
ZThjYzEzZDIzMDRhODU1NmU5NDFmMTQwNDQ3MmQxNWY3YThjNGM=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
N2ZlMTBjNGZhMzBhMWNmZDE5OWI3MWZhOTIxNGNmMDFiOGQ2YzAyYzExOWQ3
|
14
|
+
M2JmZTQxYzg4MzM2MTA0ODFmM2Y3NTcwYzY1Y2EyZjQ3MjgzMjQ5NDg4YWIx
|
15
|
+
MzA3ZDhjOTBkNTBkMTQ4Y2E1NTAyN2VmNTU0MTk4NTYxNmY2ODY=
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -13,8 +13,9 @@ Bugfixes:
|
|
13
13
|
|
14
14
|
Enhancements:
|
15
15
|
|
16
|
+
* Use an updated Ethon version. Note that from now on the `mime-types` is no longer a Ethon dependency. The gem will be still used if available to determine the mime type of a file which is uploaded. That means you have to have take care of the gem installation yourself.
|
16
17
|
* Use SVG for status badges in README.
|
17
|
-
|
18
|
+
([Sean Linsley](https://github.com/seanlinsley), [\#353](https://github.com/typhoeus/typhoeus/pull/353))
|
18
19
|
* Missing quotes in README example code.
|
19
20
|
([Jason R. Clark](https://github.com/jasonrclark), [\#351](https://github.com/typhoeus/typhoeus/pull/351))
|
20
21
|
* Specs for Faraday adapter.
|
data/README.md
CHANGED
@@ -344,6 +344,12 @@ Typhoeus.get("www.example.com", followlocation: true)
|
|
344
344
|
Typhoeus::Request.get("www.example.com", userpwd: "user:password")
|
345
345
|
```
|
346
346
|
|
347
|
+
### Compression
|
348
|
+
|
349
|
+
```ruby
|
350
|
+
Typhoeus.get("www.example.com", accept_encoding: "gzip")
|
351
|
+
```
|
352
|
+
|
347
353
|
### Cookies
|
348
354
|
|
349
355
|
```ruby
|
@@ -383,7 +389,10 @@ certificate subject is \*.host.com). You can disable host verification. Like
|
|
383
389
|
this:
|
384
390
|
|
385
391
|
```ruby
|
392
|
+
# host checking enabled
|
386
393
|
Typhoeus.get("https://www.example.com", ssl_verifyhost: 2)
|
394
|
+
# host checking disabled
|
395
|
+
Typhoeus.get("https://www.example.com", ssl_verifyhost: 0)
|
387
396
|
```
|
388
397
|
|
389
398
|
### Verbose debug output
|
@@ -49,7 +49,7 @@ module Typhoeus
|
|
49
49
|
def get
|
50
50
|
begin
|
51
51
|
easy.http_request(
|
52
|
-
request.base_url,
|
52
|
+
request.base_url.to_s,
|
53
53
|
request.options.fetch(:method, :get),
|
54
54
|
sanitize(request.options)
|
55
55
|
)
|
@@ -105,7 +105,7 @@ module Typhoeus
|
|
105
105
|
request.finish(Response.new(easy.mirror.options))
|
106
106
|
Typhoeus::Pool.release(easy)
|
107
107
|
if hydra && !hydra.queued_requests.empty?
|
108
|
-
hydra.
|
108
|
+
hydra.dequeue_many
|
109
109
|
end
|
110
110
|
end
|
111
111
|
end
|
data/lib/typhoeus/hydra.rb
CHANGED
@@ -62,6 +62,22 @@ module Typhoeus
|
|
62
62
|
def dequeue
|
63
63
|
add(queued_requests.shift) unless queued_requests.empty?
|
64
64
|
end
|
65
|
+
|
66
|
+
# Removes requests from queued_requests and
|
67
|
+
# adds them to the hydra until max_concurrency
|
68
|
+
# is reached.
|
69
|
+
#
|
70
|
+
# @example Dequeue requests.
|
71
|
+
# hydra.dequeue_many
|
72
|
+
#
|
73
|
+
# @since 0.6.8
|
74
|
+
def dequeue_many
|
75
|
+
number = multi.easy_handles.count
|
76
|
+
until number == max_concurrency || queued_requests.empty?
|
77
|
+
add(queued_requests.shift)
|
78
|
+
number += 1
|
79
|
+
end
|
80
|
+
end
|
65
81
|
end
|
66
82
|
end
|
67
83
|
end
|
@@ -11,13 +11,7 @@ module Typhoeus
|
|
11
11
|
#
|
12
12
|
# @return [ Symbol ] Return value from multi.perform.
|
13
13
|
def run
|
14
|
-
|
15
|
-
loop do
|
16
|
-
break if number_requests == max_concurrency || queued_requests.empty?
|
17
|
-
number_requests += queued_requests.pop(max_concurrency).map do |request|
|
18
|
-
add(request)
|
19
|
-
end.size
|
20
|
-
end
|
14
|
+
dequeue_many
|
21
15
|
multi.perform
|
22
16
|
end
|
23
17
|
end
|
@@ -8,8 +8,8 @@ module Typhoeus
|
|
8
8
|
# @api private
|
9
9
|
module Stubbable
|
10
10
|
|
11
|
-
# Override run in order to check for matching
|
12
|
-
# When an
|
11
|
+
# Override run in order to check for matching expectations.
|
12
|
+
# When an expectation is found, super is not called. Instead a
|
13
13
|
# canned response is assigned to the request.
|
14
14
|
#
|
15
15
|
# @example Run the request.
|
data/lib/typhoeus/version.rb
CHANGED
@@ -82,13 +82,13 @@ describe "Rack::Typhoeus::Middleware::ParamsDecoder::Helper" do
|
|
82
82
|
context "and its 0" do
|
83
83
|
let(:params){ {'0' => 1} }
|
84
84
|
it 'returns true' do
|
85
|
-
expect(encoded).to
|
85
|
+
expect(encoded).to be_truthy
|
86
86
|
end
|
87
87
|
end
|
88
88
|
context "and its not 0" do
|
89
89
|
let(:params){ {'some-key' => 1}}
|
90
90
|
it 'returns false' do
|
91
|
-
expect(encoded).to
|
91
|
+
expect(encoded).to be_falsey
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
@@ -97,7 +97,7 @@ describe "Rack::Typhoeus::Middleware::ParamsDecoder::Helper" do
|
|
97
97
|
let(:params) { Hash[12.times.map {|i| [i, (i+65).chr]}] }
|
98
98
|
|
99
99
|
it "returns true" do
|
100
|
-
expect(encoded).to
|
100
|
+
expect(encoded).to be_truthy
|
101
101
|
end
|
102
102
|
end
|
103
103
|
|
@@ -105,7 +105,7 @@ describe "Rack::Typhoeus::Middleware::ParamsDecoder::Helper" do
|
|
105
105
|
let(:params) { {:a => 1} }
|
106
106
|
|
107
107
|
it "returns false" do
|
108
|
-
expect(encoded).to
|
108
|
+
expect(encoded).to be_falsey
|
109
109
|
end
|
110
110
|
end
|
111
111
|
end
|
@@ -84,7 +84,7 @@ describe Faraday::Adapter::Typhoeus do
|
|
84
84
|
let(:env) { { :method => :get, :ssl => {}, :request => {} } }
|
85
85
|
|
86
86
|
it "falls back to single" do
|
87
|
-
Typhoeus::Request.
|
87
|
+
expect(Typhoeus::Request).to receive(:new).and_return(double(:options => {}, :on_complete => [], :run => true))
|
88
88
|
adapter.method(:perform_request).call(env)
|
89
89
|
end
|
90
90
|
end
|
@@ -119,7 +119,7 @@ describe Faraday::Adapter::Typhoeus do
|
|
119
119
|
end
|
120
120
|
|
121
121
|
it "sets on_complete callback" do
|
122
|
-
expect(request.on_complete).to
|
122
|
+
expect(request.on_complete.size).to eq(1)
|
123
123
|
end
|
124
124
|
end
|
125
125
|
|
@@ -256,7 +256,7 @@ describe Faraday::Adapter::Typhoeus do
|
|
256
256
|
end
|
257
257
|
|
258
258
|
it "sets ssl_verifypeer to false" do
|
259
|
-
expect(request.options[:ssl_verifypeer]).to
|
259
|
+
expect(request.options[:ssl_verifypeer]).to be_falsey
|
260
260
|
end
|
261
261
|
end
|
262
262
|
|
@@ -268,7 +268,7 @@ describe Faraday::Adapter::Typhoeus do
|
|
268
268
|
end
|
269
269
|
|
270
270
|
it "sets ssl_verifypeer to true" do
|
271
|
-
expect(request.options[:ssl_verifypeer]).to
|
271
|
+
expect(request.options[:ssl_verifypeer]).to be_truthy
|
272
272
|
end
|
273
273
|
end
|
274
274
|
end
|
@@ -278,7 +278,7 @@ describe Faraday::Adapter::Typhoeus do
|
|
278
278
|
let(:env) { { :parallel_manager => true } }
|
279
279
|
|
280
280
|
it "returns true" do
|
281
|
-
expect(adapter.method(:parallel?).call(env)).to
|
281
|
+
expect(adapter.method(:parallel?).call(env)).to be_truthy
|
282
282
|
end
|
283
283
|
end
|
284
284
|
|
@@ -286,7 +286,7 @@ describe Faraday::Adapter::Typhoeus do
|
|
286
286
|
let(:env) { { :parallel_manager => nil } }
|
287
287
|
|
288
288
|
it "returns false" do
|
289
|
-
expect(adapter.method(:parallel?).call(env)).to
|
289
|
+
expect(adapter.method(:parallel?).call(env)).to be_falsey
|
290
290
|
end
|
291
291
|
end
|
292
292
|
end
|
@@ -2,7 +2,7 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Typhoeus::EasyFactory do
|
4
4
|
let(:base_url) { "http://localhost:3001" }
|
5
|
-
let(:hydra) { Typhoeus::Hydra.new(:max_concurrency =>
|
5
|
+
let(:hydra) { Typhoeus::Hydra.new(:max_concurrency => 1) }
|
6
6
|
let(:options) { {} }
|
7
7
|
let(:request) { Typhoeus::Request.new(base_url, options) }
|
8
8
|
let(:easy_factory) { described_class.new(request, hydra) }
|
@@ -48,15 +48,15 @@ describe Typhoeus::EasyFactory do
|
|
48
48
|
let(:options) { {:connect_timeout => 1} }
|
49
49
|
|
50
50
|
it "warns" do
|
51
|
-
easy_factory.
|
51
|
+
expect(easy_factory).to receive(:warn).with(
|
52
52
|
"Deprecated option connect_timeout. Please use connecttimeout instead."
|
53
53
|
)
|
54
54
|
easy_factory.get
|
55
55
|
end
|
56
56
|
|
57
57
|
it "passes correct option" do
|
58
|
-
easy_factory.
|
59
|
-
easy_factory.easy.
|
58
|
+
expect(easy_factory).to receive(:warn)
|
59
|
+
expect(easy_factory.easy).to receive(:connecttimeout=).with(1)
|
60
60
|
easy_factory.get
|
61
61
|
end
|
62
62
|
end
|
@@ -64,19 +64,19 @@ describe Typhoeus::EasyFactory do
|
|
64
64
|
|
65
65
|
describe "#set_callback" do
|
66
66
|
it "sets easy.on_complete callback" do
|
67
|
-
easy_factory.easy.
|
67
|
+
expect(easy_factory.easy).to receive(:on_complete)
|
68
68
|
easy_factory.send(:set_callback)
|
69
69
|
end
|
70
70
|
|
71
71
|
it "finishes request" do
|
72
72
|
easy_factory.send(:set_callback)
|
73
|
-
request.
|
73
|
+
expect(request).to receive(:finish)
|
74
74
|
easy_factory.easy.complete
|
75
75
|
end
|
76
76
|
|
77
77
|
it "resets easy" do
|
78
78
|
easy_factory.send(:set_callback)
|
79
|
-
easy_factory.easy.
|
79
|
+
expect(easy_factory.easy).to receive(:reset)
|
80
80
|
easy_factory.easy.complete
|
81
81
|
end
|
82
82
|
|
@@ -88,7 +88,7 @@ describe Typhoeus::EasyFactory do
|
|
88
88
|
|
89
89
|
it "adds next request" do
|
90
90
|
easy_factory.hydra.instance_variable_set(:@queued_requests, [request])
|
91
|
-
easy_factory.hydra.
|
91
|
+
expect(easy_factory.hydra).to receive(:add).with(request)
|
92
92
|
easy_factory.send(:set_callback)
|
93
93
|
easy_factory.easy.complete
|
94
94
|
end
|
@@ -40,7 +40,7 @@ describe Typhoeus::Expectation do
|
|
40
40
|
let(:expectations) { double(:clear) }
|
41
41
|
|
42
42
|
it "clears all" do
|
43
|
-
expectations.
|
43
|
+
expect(expectations).to receive(:clear)
|
44
44
|
Typhoeus::Expectation.instance_variable_set(:@expectations, expectations)
|
45
45
|
Typhoeus::Expectation.clear
|
46
46
|
Typhoeus::Expectation.instance_variable_set(:@expectations, nil)
|
@@ -53,8 +53,8 @@ describe Typhoeus::Expectation do
|
|
53
53
|
|
54
54
|
it "finds a matching expectation and returns its next response" do
|
55
55
|
Typhoeus::Expectation.all << expectation
|
56
|
-
expectation.
|
57
|
-
expectation.
|
56
|
+
expect(expectation).to receive(:matches?).with(request).and_return(true)
|
57
|
+
expect(expectation).to receive(:response).with(request).and_return(stubbed_response)
|
58
58
|
|
59
59
|
response = Typhoeus::Expectation.response_for(request)
|
60
60
|
|
@@ -88,7 +88,7 @@ describe Typhoeus::Expectation do
|
|
88
88
|
|
89
89
|
context "when array" do
|
90
90
|
it "adds to responses" do
|
91
|
-
|
91
|
+
skip
|
92
92
|
expectation.and_return([1, 2])
|
93
93
|
expect(expectation.responses).to eq([1, 2])
|
94
94
|
end
|
@@ -154,13 +154,13 @@ describe Typhoeus::Expectation do
|
|
154
154
|
let(:request) { double(:base_url => nil) }
|
155
155
|
|
156
156
|
it "calls url_match?" do
|
157
|
-
expectation.
|
157
|
+
expect(expectation).to receive(:url_match?)
|
158
158
|
expectation.matches?(request)
|
159
159
|
end
|
160
160
|
|
161
161
|
it "calls options_match?" do
|
162
|
-
expectation.
|
163
|
-
expectation.
|
162
|
+
expect(expectation).to receive(:url_match?).and_return(true)
|
163
|
+
expect(expectation).to receive(:options_match?)
|
164
164
|
expectation.matches?(request)
|
165
165
|
end
|
166
166
|
end
|
@@ -173,7 +173,7 @@ describe Typhoeus::Expectation do
|
|
173
173
|
context "when string" do
|
174
174
|
context "when match" do
|
175
175
|
it "returns true" do
|
176
|
-
expect(url_match).to
|
176
|
+
expect(url_match).to be_truthy
|
177
177
|
end
|
178
178
|
end
|
179
179
|
|
@@ -181,7 +181,7 @@ describe Typhoeus::Expectation do
|
|
181
181
|
let(:base_url) { "no_match" }
|
182
182
|
|
183
183
|
it "returns false" do
|
184
|
-
expect(url_match).to
|
184
|
+
expect(url_match).to be_falsey
|
185
185
|
end
|
186
186
|
end
|
187
187
|
end
|
@@ -191,7 +191,7 @@ describe Typhoeus::Expectation do
|
|
191
191
|
let(:base_url) { /example/ }
|
192
192
|
|
193
193
|
it "returns true" do
|
194
|
-
expect(url_match).to
|
194
|
+
expect(url_match).to be_truthy
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
@@ -199,7 +199,7 @@ describe Typhoeus::Expectation do
|
|
199
199
|
let(:base_url) { /nomatch/ }
|
200
200
|
|
201
201
|
it "returns false" do
|
202
|
-
expect(url_match).to
|
202
|
+
expect(url_match).to be_falsey
|
203
203
|
end
|
204
204
|
end
|
205
205
|
end
|
@@ -208,7 +208,7 @@ describe Typhoeus::Expectation do
|
|
208
208
|
let(:base_url) { nil }
|
209
209
|
|
210
210
|
it "returns true" do
|
211
|
-
expect(url_match).to
|
211
|
+
expect(url_match).to be_truthy
|
212
212
|
end
|
213
213
|
end
|
214
214
|
|
@@ -216,7 +216,7 @@ describe Typhoeus::Expectation do
|
|
216
216
|
let(:base_url) { 1 }
|
217
217
|
|
218
218
|
it "returns false" do
|
219
|
-
expect(url_match).to
|
219
|
+
expect(url_match).to be_falsey
|
220
220
|
end
|
221
221
|
end
|
222
222
|
end
|
@@ -231,7 +231,7 @@ describe Typhoeus::Expectation do
|
|
231
231
|
let(:request_options) { options }
|
232
232
|
|
233
233
|
it "returns true" do
|
234
|
-
expect(options_match).to
|
234
|
+
expect(options_match).to be_truthy
|
235
235
|
end
|
236
236
|
end
|
237
237
|
|
@@ -240,7 +240,7 @@ describe Typhoeus::Expectation do
|
|
240
240
|
let(:request_options) { { :a => 1, :b => 2 } }
|
241
241
|
|
242
242
|
it "returns true" do
|
243
|
-
expect(options_match).to
|
243
|
+
expect(options_match).to be_truthy
|
244
244
|
end
|
245
245
|
end
|
246
246
|
|
@@ -249,7 +249,7 @@ describe Typhoeus::Expectation do
|
|
249
249
|
let(:request_options) { options }
|
250
250
|
|
251
251
|
it "returns true" do
|
252
|
-
expect(options_match).to
|
252
|
+
expect(options_match).to be_truthy
|
253
253
|
end
|
254
254
|
end
|
255
255
|
|
@@ -258,7 +258,7 @@ describe Typhoeus::Expectation do
|
|
258
258
|
let(:request_options) { options }
|
259
259
|
|
260
260
|
it "returns true" do
|
261
|
-
expect(options_match).to
|
261
|
+
expect(options_match).to be_truthy
|
262
262
|
end
|
263
263
|
end
|
264
264
|
|
@@ -266,7 +266,7 @@ describe Typhoeus::Expectation do
|
|
266
266
|
let(:options) { { :a => 1 } }
|
267
267
|
|
268
268
|
it "returns false" do
|
269
|
-
expect(options_match).to
|
269
|
+
expect(options_match).to be_falsey
|
270
270
|
end
|
271
271
|
end
|
272
272
|
end
|