typhoeus 0.6.5 → 0.6.6
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.
- data/.travis.yml +7 -0
- data/CHANGELOG.md +10 -2
- data/README.md +8 -2
- data/lib/typhoeus/adapters/faraday.rb +3 -2
- data/lib/typhoeus/hydra.rb +0 -3
- data/lib/typhoeus/hydra/queueable.rb +11 -0
- data/lib/typhoeus/request.rb +11 -0
- data/lib/typhoeus/response.rb +1 -0
- data/lib/typhoeus/response/informations.rb +9 -3
- data/lib/typhoeus/version.rb +1 -1
- data/spec/typhoeus/adapters/faraday_spec.rb +25 -1
- data/spec/typhoeus/hydra/queueable_spec.rb +5 -0
- data/spec/typhoeus/request_spec.rb +18 -5
- data/spec/typhoeus/response/informations_spec.rb +43 -5
- data/typhoeus.gemspec +1 -1
- metadata +15 -7
- checksums.yaml +0 -15
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,9 +2,17 @@
|
|
2
2
|
|
3
3
|
## Master
|
4
4
|
|
5
|
-
[Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.6.
|
5
|
+
[Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.6.6...master)
|
6
6
|
|
7
|
-
##
|
7
|
+
## 0.6.6
|
8
|
+
|
9
|
+
[Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.6.5...v0.6.6)
|
10
|
+
|
11
|
+
## 0.6.5
|
12
|
+
|
13
|
+
[Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.6.4...v0.6.5)
|
14
|
+
|
15
|
+
## 0.6.4
|
8
16
|
|
9
17
|
[Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.6.3...v0.6.4)
|
10
18
|
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Typhoeus [](http://travis-ci.org/typhoeus/typhoeus) [](https://codeclimate.com/github/typhoeus/typhoeus)
|
1
|
+
# Typhoeus [](http://travis-ci.org/typhoeus/typhoeus) [](https://codeclimate.com/github/typhoeus/typhoeus) [](http://badge.fury.io/rb/typhoeus)
|
2
2
|
|
3
3
|
Like a modern code version of the mythical beast with 100 serpent heads, Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic.
|
4
4
|
|
@@ -74,7 +74,7 @@ The response object will be set after the request is run.
|
|
74
74
|
response = request.response
|
75
75
|
response.code
|
76
76
|
response.total_time
|
77
|
-
response.
|
77
|
+
response.headers_hash
|
78
78
|
response.body
|
79
79
|
```
|
80
80
|
|
@@ -253,6 +253,12 @@ No exceptions are raised on HTTP timeouts. You can check whether a request timed
|
|
253
253
|
Typhoeus.get("www.example.com").timed_out?
|
254
254
|
```
|
255
255
|
|
256
|
+
There are two different timeouts available: [`timeout`](http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTTIMEOUT)
|
257
|
+
and [`connecttimeout`](http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTCONNECTTIMEOUT). `timeout` is the
|
258
|
+
maximum time in seconds that you allow the libcurl transfer operation to take and `connecttimeout` is the maximum
|
259
|
+
time in seconds that you allow the connection to the server to take. These two are always available, while `timeout_ms` ond
|
260
|
+
`connecttimeout_ms` accept milliseconds but only an option when curl is build with `c-ares`, it will use `timout` or `connecttimeout` otherwise.
|
261
|
+
|
256
262
|
### Following Redirections
|
257
263
|
|
258
264
|
Use `followlocation: true`, eg:
|
@@ -120,6 +120,7 @@ module Faraday # :nodoc:
|
|
120
120
|
req.options[:sslkey] = ssl[:client_key] if ssl[:client_key]
|
121
121
|
req.options[:cainfo] = ssl[:ca_file] if ssl[:ca_file]
|
122
122
|
req.options[:capath] = ssl[:ca_path] if ssl[:ca_path]
|
123
|
+
req.options[:keypasswd] = ssl[:client_cert_passwd] if ssl[:client_cert_passwd]
|
123
124
|
end
|
124
125
|
|
125
126
|
def configure_proxy(req, env)
|
@@ -128,8 +129,8 @@ module Faraday # :nodoc:
|
|
128
129
|
|
129
130
|
req.options[:proxy] = "#{proxy[:uri].host}:#{proxy[:uri].port}"
|
130
131
|
|
131
|
-
if proxy[:
|
132
|
-
req.options[:proxyuserpwd] = "#{proxy[:
|
132
|
+
if proxy[:user] && proxy[:password]
|
133
|
+
req.options[:proxyuserpwd] = "#{proxy[:user]}:#{proxy[:password]}"
|
133
134
|
end
|
134
135
|
end
|
135
136
|
|
data/lib/typhoeus/hydra.rb
CHANGED
@@ -40,6 +40,17 @@ module Typhoeus
|
|
40
40
|
queued_requests << request
|
41
41
|
end
|
42
42
|
|
43
|
+
# Pushes a request to the front of the queue,
|
44
|
+
# to be performed by the hydra. Also sets hydra
|
45
|
+
# on request
|
46
|
+
#
|
47
|
+
# @example Queue reques.
|
48
|
+
# hydra.queue_front(request)
|
49
|
+
def queue_front(request)
|
50
|
+
request.hydra = self
|
51
|
+
queued_requests.unshift request
|
52
|
+
end
|
53
|
+
|
43
54
|
# Removes a request from queued_requests and
|
44
55
|
# adds it to the hydra in order to be
|
45
56
|
# performed next.
|
data/lib/typhoeus/request.rb
CHANGED
@@ -155,6 +155,17 @@ module Typhoeus
|
|
155
155
|
Zlib.crc32 "#{self.class.name}#{base_url}#{options}"
|
156
156
|
end
|
157
157
|
|
158
|
+
# Mimics libcurls POST body generation. This is not accurate, but good
|
159
|
+
# enough for VCR.
|
160
|
+
#
|
161
|
+
# @return [ String ] The encoded body.
|
162
|
+
# otherwise.
|
163
|
+
#
|
164
|
+
# @api private
|
165
|
+
def encoded_body
|
166
|
+
Ethon::Easy::Form.new(nil, options[:body]).to_s
|
167
|
+
end
|
168
|
+
|
158
169
|
private
|
159
170
|
|
160
171
|
# Checks if two hashes are equal or not, discarding
|
data/lib/typhoeus/response.rb
CHANGED
@@ -24,7 +24,7 @@ module Typhoeus
|
|
24
24
|
#
|
25
25
|
# @since 0.6.2
|
26
26
|
def return_message
|
27
|
-
Ethon::Curl.easy_strerror(return_code)
|
27
|
+
Ethon::Curl.easy_strerror(return_code) if return_code
|
28
28
|
end
|
29
29
|
|
30
30
|
# Return the http response body.
|
@@ -45,7 +45,12 @@ module Typhoeus
|
|
45
45
|
#
|
46
46
|
# @return [ String ] The response_headers.
|
47
47
|
def response_headers
|
48
|
-
options[:response_headers]
|
48
|
+
return options[:response_headers] if options[:response_headers]
|
49
|
+
if mock? && h = options[:headers]
|
50
|
+
h.map{ |k,v| [k, v.respond_to?(:join) ? v.join : v] }.
|
51
|
+
map{ |e| "#{e.first}: #{e.last}" }.
|
52
|
+
join("\r\n")
|
53
|
+
end
|
49
54
|
end
|
50
55
|
|
51
56
|
# Return the last received HTTP, FTP or SMTP response code.
|
@@ -199,8 +204,9 @@ module Typhoeus
|
|
199
204
|
#
|
200
205
|
# @return [ Typhoeus::Header ] The response header.
|
201
206
|
def headers
|
207
|
+
return Header.new(options[:headers]) if mock? && options[:headers]
|
202
208
|
return nil if response_headers.nil? && !defined?(@headers)
|
203
|
-
@headers ||=
|
209
|
+
@headers ||= Header.new(response_headers.split("\r\n\r\n").last)
|
204
210
|
end
|
205
211
|
alias :headers_hash :headers
|
206
212
|
|
data/lib/typhoeus/version.rb
CHANGED
@@ -36,6 +36,30 @@ describe Faraday::Adapter::Typhoeus do
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
+
context "when a response is stubbed" do
|
40
|
+
before do
|
41
|
+
stub = Typhoeus::Response.new \
|
42
|
+
:code => 200,
|
43
|
+
:headers => { "Foo" => "2", "Bar" => "3" },
|
44
|
+
:body => "Hello",
|
45
|
+
:mock => true
|
46
|
+
|
47
|
+
Typhoeus.stub(base_url + '/').and_return(stub)
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'stubs the status code' do
|
51
|
+
expect(response.status).to eq(200)
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'stubs the response body' do
|
55
|
+
expect(response.body).to eq("Hello")
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'stubs the headers' do
|
59
|
+
expect(response.headers).to eq("Foo" => "2", "Bar" => "3")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
39
63
|
describe "#perform_request" do
|
40
64
|
let(:env) { {} }
|
41
65
|
|
@@ -145,7 +169,7 @@ describe Faraday::Adapter::Typhoeus do
|
|
145
169
|
let(:env) do
|
146
170
|
{ :request => { :proxy => {
|
147
171
|
:uri => double(:host => :a, :port => :b),
|
148
|
-
:
|
172
|
+
:user => "a",
|
149
173
|
:password => "b"
|
150
174
|
} } }
|
151
175
|
end
|
@@ -21,6 +21,11 @@ describe Typhoeus::Hydra::Queueable do
|
|
21
21
|
hydra.queue(request)
|
22
22
|
expect(hydra.queued_requests).to include(request)
|
23
23
|
end
|
24
|
+
|
25
|
+
it "adds to front of queued requests" do
|
26
|
+
hydra.queue_front(request)
|
27
|
+
expect(hydra.queued_requests.first).to be(request)
|
28
|
+
end
|
24
29
|
end
|
25
30
|
|
26
31
|
describe "#abort" do
|
@@ -7,9 +7,9 @@ describe Typhoeus::Request do
|
|
7
7
|
|
8
8
|
describe ".url" do
|
9
9
|
context "when no parameters" do
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
it "returns base_url" do
|
11
|
+
expect(request.url).to eq(request.base_url)
|
12
|
+
end
|
13
13
|
end
|
14
14
|
|
15
15
|
context "when parameters" do
|
@@ -49,7 +49,8 @@ describe Typhoeus::Request do
|
|
49
49
|
let(:options) { {:headers => {} } }
|
50
50
|
|
51
51
|
it "add user agent" do
|
52
|
-
|
52
|
+
agent = request.options[:headers]['User-Agent']
|
53
|
+
expect(agent).to eq(Typhoeus::USER_AGENT)
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
@@ -100,7 +101,9 @@ describe Typhoeus::Request do
|
|
100
101
|
end
|
101
102
|
|
102
103
|
context "when different order" do
|
103
|
-
let(:other_options) {
|
104
|
+
let(:other_options) {
|
105
|
+
{:headers => { 'User-Agent' => "Fubar" }, :verbose => true }
|
106
|
+
}
|
104
107
|
let(:other) { Typhoeus::Request.new(base_url, other_options)}
|
105
108
|
|
106
109
|
it "returns true" do
|
@@ -128,4 +131,14 @@ describe Typhoeus::Request do
|
|
128
131
|
end
|
129
132
|
end
|
130
133
|
end
|
134
|
+
|
135
|
+
describe "#encoded_body" do
|
136
|
+
let(:request) {
|
137
|
+
Typhoeus::Request.new("www.example.com",:body => {:a => 1})
|
138
|
+
}
|
139
|
+
|
140
|
+
it "returns encoded body" do
|
141
|
+
expect(request.encoded_body).to eq("a=1")
|
142
|
+
end
|
143
|
+
end
|
131
144
|
end
|
@@ -26,6 +26,14 @@ describe Typhoeus::Response::Informations do
|
|
26
26
|
it "returns a message" do
|
27
27
|
expect(response.return_message).to eq("Couldn't connect to server")
|
28
28
|
end
|
29
|
+
|
30
|
+
describe "with nil return_code" do
|
31
|
+
let(:options) { { :return_code => nil } }
|
32
|
+
|
33
|
+
it "returns nil" do
|
34
|
+
expect(response.return_message).to be_nil
|
35
|
+
end
|
36
|
+
end
|
29
37
|
end
|
30
38
|
|
31
39
|
describe "#response_body" do
|
@@ -47,10 +55,26 @@ describe Typhoeus::Response::Informations do
|
|
47
55
|
end
|
48
56
|
|
49
57
|
describe "#response_headers" do
|
50
|
-
let(:options) { { :response_headers => "
|
58
|
+
let(:options) { { :response_headers => "Length: 1" } }
|
59
|
+
|
60
|
+
context "when no mock" do
|
61
|
+
it "returns response_headers from options" do
|
62
|
+
expect(response.response_headers).to eq("Length: 1")
|
63
|
+
end
|
64
|
+
end
|
51
65
|
|
52
|
-
|
53
|
-
|
66
|
+
context "when mock" do
|
67
|
+
context "when no response_headers" do
|
68
|
+
context "when headers" do
|
69
|
+
let(:options) { { :mock => true, :headers => {"Length" => 1, "Content-Type" => "text/plain" } } }
|
70
|
+
|
71
|
+
it "constructs response_headers" do
|
72
|
+
expect(response.response_headers).to include("Length: 1")
|
73
|
+
expect(response.response_headers).to include("Content-Type: text/plain")
|
74
|
+
expect(response.response_headers).to include("\r\n")
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
54
78
|
end
|
55
79
|
end
|
56
80
|
|
@@ -153,13 +177,13 @@ describe Typhoeus::Response::Informations do
|
|
153
177
|
end
|
154
178
|
|
155
179
|
describe "#headers" do
|
156
|
-
context "when no
|
180
|
+
context "when no response_headers" do
|
157
181
|
it "returns nil" do
|
158
182
|
expect(response.headers).to be_nil
|
159
183
|
end
|
160
184
|
end
|
161
185
|
|
162
|
-
context "when
|
186
|
+
context "when response_headers" do
|
163
187
|
let(:options) { {:response_headers => "Expire: -1\nServer: gws"} }
|
164
188
|
|
165
189
|
it "returns nonempty headers" do
|
@@ -183,6 +207,20 @@ describe Typhoeus::Response::Informations do
|
|
183
207
|
end
|
184
208
|
end
|
185
209
|
|
210
|
+
context "when mock" do
|
211
|
+
context "when headers" do
|
212
|
+
let(:options) { {:mock => true, :headers => {"Length" => "1"}} }
|
213
|
+
|
214
|
+
it "returns Typhoeus::Response::Header" do
|
215
|
+
expect(response.headers).to be_a(Typhoeus::Response::Header)
|
216
|
+
end
|
217
|
+
|
218
|
+
it "returns headers" do
|
219
|
+
expect(response.headers).to include("Length" => "1")
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
186
224
|
context "when requesting" do
|
187
225
|
let(:response) { Typhoeus.get("localhost:3001") }
|
188
226
|
|
data/typhoeus.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.description = %q{Like a modern code version of the mythical beast with 100 serpent heads, Typhoeus runs HTTP requests in parallel while cleanly encapsulating handling logic.}
|
16
16
|
|
17
17
|
s.required_rubygems_version = ">= 1.3.6"
|
18
|
-
s.
|
18
|
+
s.license = 'MIT'
|
19
19
|
|
20
20
|
s.add_dependency('ethon', ["~> 0.6.1"])
|
21
21
|
|
metadata
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: typhoeus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.6.
|
4
|
+
version: 0.6.6
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- David Balatero
|
@@ -10,11 +11,12 @@ authors:
|
|
10
11
|
autorequire:
|
11
12
|
bindir: bin
|
12
13
|
cert_chain: []
|
13
|
-
date: 2013-
|
14
|
+
date: 2013-10-31 00:00:00.000000000 Z
|
14
15
|
dependencies:
|
15
16
|
- !ruby/object:Gem::Dependency
|
16
17
|
name: ethon
|
17
18
|
requirement: !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
18
20
|
requirements:
|
19
21
|
- - ~>
|
20
22
|
- !ruby/object:Gem::Version
|
@@ -22,6 +24,7 @@ dependencies:
|
|
22
24
|
type: :runtime
|
23
25
|
prerelease: false
|
24
26
|
version_requirements: !ruby/object:Gem::Requirement
|
27
|
+
none: false
|
25
28
|
requirements:
|
26
29
|
- - ~>
|
27
30
|
- !ruby/object:Gem::Version
|
@@ -123,27 +126,32 @@ files:
|
|
123
126
|
- spec/typhoeus_spec.rb
|
124
127
|
- typhoeus.gemspec
|
125
128
|
homepage: https://github.com/typhoeus/typhoeus
|
126
|
-
licenses:
|
127
|
-
|
129
|
+
licenses:
|
130
|
+
- MIT
|
128
131
|
post_install_message:
|
129
132
|
rdoc_options: []
|
130
133
|
require_paths:
|
131
134
|
- lib
|
132
135
|
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
133
137
|
requirements:
|
134
138
|
- - ! '>='
|
135
139
|
- !ruby/object:Gem::Version
|
136
140
|
version: '0'
|
141
|
+
segments:
|
142
|
+
- 0
|
143
|
+
hash: -806955660153474198
|
137
144
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
145
|
+
none: false
|
138
146
|
requirements:
|
139
147
|
- - ! '>='
|
140
148
|
- !ruby/object:Gem::Version
|
141
149
|
version: 1.3.6
|
142
150
|
requirements: []
|
143
|
-
rubyforge_project:
|
144
|
-
rubygems_version:
|
151
|
+
rubyforge_project:
|
152
|
+
rubygems_version: 1.8.23
|
145
153
|
signing_key:
|
146
|
-
specification_version:
|
154
|
+
specification_version: 3
|
147
155
|
summary: Parallel HTTP library on top of libcurl multi.
|
148
156
|
test_files:
|
149
157
|
- spec/rack/typhoeus/middleware/params_decoder/helper_spec.rb
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
ZDdmYjM1MjNhYzZkNWViZjdiMGE2YjUzYjQzMzJjMTk4YzI4ODNlNA==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
N2Y3MTBjOGViOGExMDI1Mjk3MjkyOWJiYTA4OWM3N2M5NWRlM2Y4NA==
|
7
|
-
!binary "U0hBNTEy":
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
MDQxZDBmNWM2N2RkY2Y2NWEwZDBjNGQ1YTZlNTUwZmYwMDNlN2MzNzIwN2Fi
|
10
|
-
N2RjMjQ5NDZiZTU0ZjBlZDQ0NTc4ZDEwMTNiZTljNmZmOTQxYWM2NzAwNDcw
|
11
|
-
ZWUxZDcyNTExMTkxZTE4ZjcxMjM5OTUxNWNiOWExZTUwNDk3NjI=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YjBlZTkxNzQ1Y2Y3ODQ0NGNlODNiMmM0MmMxYWMwY2I5M2MwYTgxMDZkZjdl
|
14
|
-
OWZkNTNlYTE5OTI3Njk4YzU3N2U3ZDIwNDU5ODhiOTk0YWEwMzQ3Y2NmM2Rh
|
15
|
-
Zjc2OTFhMzRhYmE3ZTEyMjQ4OGIwMDUyNDk1Y2EwYjgwNDY2OTI=
|