typhoeus 0.8.0 → 1.0.0
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 +4 -4
- data/.travis.yml +1 -0
- data/CHANGELOG.md +21 -1
- data/lib/typhoeus/adapters/faraday.rb +9 -5
- data/lib/typhoeus/easy_factory.rb +33 -36
- data/lib/typhoeus/expectation.rb +1 -1
- data/lib/typhoeus/hydra.rb +1 -1
- data/lib/typhoeus/request.rb +3 -7
- data/lib/typhoeus/request/streamable.rb +1 -1
- data/lib/typhoeus/response/cacheable.rb +1 -1
- data/lib/typhoeus/response/header.rb +11 -7
- data/lib/typhoeus/response/status.rb +2 -2
- data/lib/typhoeus/version.rb +1 -1
- data/spec/typhoeus/hydra/queueable_spec.rb +10 -0
- data/spec/typhoeus/response/status_spec.rb +0 -16
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d43b52d7dfc8cb4542b1670f07f43351906129ba
|
4
|
+
data.tar.gz: 3ff1f2870c76247f16ce94c00e7f534dafe6c879
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fda1a066fe0e0d0a6c078540d85b87739fe7e24907b92e272dc86d473cc9d6a01bc726047f942efc5a7a1a35da62dcfe2bff10c952469c464174ab1592d1c10c
|
7
|
+
data.tar.gz: d407bebd52067ed31b54e4b72a5d5e8ce65f9d43b9fe17e00fd4e7ae024bff905f95ff268e6ca22d2aad90a8fec440c1d69ae9171c83ed68c832831a5699c703
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -2,7 +2,27 @@
|
|
2
2
|
|
3
3
|
## Master
|
4
4
|
|
5
|
-
[Full Changelog](http://github.com/typhoeus/typhoeus/compare/
|
5
|
+
[Full Changelog](http://github.com/typhoeus/typhoeus/compare/v1.0.0...master)
|
6
|
+
|
7
|
+
## 1.0.0
|
8
|
+
|
9
|
+
[Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.8.0...v1.0.0)
|
10
|
+
|
11
|
+
## O.8.0
|
12
|
+
|
13
|
+
[Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.7.3...v0.8.0)
|
14
|
+
|
15
|
+
* `EasyFactory`: Reduced object allocations and method calls during deprecated
|
16
|
+
option handling and option sanitization.
|
17
|
+
([Tasos Laskos](https://github.com/zapotek))
|
18
|
+
* `Response` ([Tasos Laskos](https://github.com/zapotek))
|
19
|
+
* `Header`
|
20
|
+
* `#process_pair`: Halved `#set_value` calls.
|
21
|
+
* `#set_value`: Minimized `Hash` accesses.
|
22
|
+
* `#parse`: Use `String#start_with?` instead of `Regexp` match.
|
23
|
+
* `#process_line`: Optimized key/value sanitization.
|
24
|
+
* `Status`
|
25
|
+
* `#timed_out?`: Only return `true` when `#return_code` is `operation_timedout`.
|
6
26
|
|
7
27
|
## 0.7.3
|
8
28
|
|
@@ -86,11 +86,15 @@ module Faraday # :nodoc:
|
|
86
86
|
|
87
87
|
req.on_complete do |resp|
|
88
88
|
if resp.timed_out?
|
89
|
-
|
90
|
-
|
91
|
-
else
|
89
|
+
env[:typhoeus_timed_out] = true
|
90
|
+
unless parallel?(env)
|
92
91
|
raise Faraday::Error::TimeoutError, "request timed out"
|
93
92
|
end
|
93
|
+
elsif resp.response_code == 0
|
94
|
+
env[:typhoeus_connection_failed] = true
|
95
|
+
unless parallel?(env)
|
96
|
+
raise Faraday::Error::ConnectionFailed, resp.return_message
|
97
|
+
end
|
94
98
|
end
|
95
99
|
|
96
100
|
save_response(env, resp.code, resp.body) do |response_headers|
|
@@ -137,8 +141,8 @@ module Faraday # :nodoc:
|
|
137
141
|
|
138
142
|
def configure_timeout(req, env)
|
139
143
|
env_req = env[:request]
|
140
|
-
req.options[:timeout_ms] = (env_req[:timeout] * 1000) if env_req[:timeout]
|
141
|
-
req.options[:connecttimeout_ms] = (env_req[:open_timeout] * 1000) if env_req[:open_timeout]
|
144
|
+
req.options[:timeout_ms] = (env_req[:timeout] * 1000).to_i if env_req[:timeout]
|
145
|
+
req.options[:connecttimeout_ms] = (env_req[:open_timeout] * 1000).to_i if env_req[:open_timeout]
|
142
146
|
end
|
143
147
|
|
144
148
|
def configure_socket(req, env)
|
@@ -8,6 +8,34 @@ module Typhoeus
|
|
8
8
|
# @api private
|
9
9
|
class EasyFactory
|
10
10
|
|
11
|
+
RENAMED_OPTIONS = {
|
12
|
+
:auth_method => :httpauth,
|
13
|
+
:connect_timeout => :connecttimeout,
|
14
|
+
:encoding => :accept_encoding,
|
15
|
+
:follow_location => :followlocation,
|
16
|
+
:max_redirects => :maxredirs,
|
17
|
+
:proxy_type => :proxytype,
|
18
|
+
:ssl_cacert => :cainfo,
|
19
|
+
:ssl_capath => :capath,
|
20
|
+
:ssl_cert => :sslcert,
|
21
|
+
:ssl_cert_type => :sslcerttype,
|
22
|
+
:ssl_key => :sslkey,
|
23
|
+
:ssl_key_password => :keypasswd,
|
24
|
+
:ssl_key_type => :sslkeytype,
|
25
|
+
:ssl_version => :sslversion,
|
26
|
+
}
|
27
|
+
|
28
|
+
CHANGED_OPTIONS = {
|
29
|
+
:disable_ssl_host_verification => :ssl_verifyhost,
|
30
|
+
:disable_ssl_peer_verification => :ssl_verifypeer,
|
31
|
+
:proxy_auth_method => :proxyauth,
|
32
|
+
}
|
33
|
+
|
34
|
+
REMOVED_OPTIONS = Set.new([:cache_key_basis, :cache_timeout, :user_agent])
|
35
|
+
|
36
|
+
SANITIZE_IGNORE = Set.new([:method, :cache_ttl])
|
37
|
+
SANITIZE_TIMEOUT = Set.new([:timeout_ms, :connecttimeout_ms])
|
38
|
+
|
11
39
|
# Returns the request provided.
|
12
40
|
#
|
13
41
|
# @return [ Typhoeus::Request ]
|
@@ -69,12 +97,12 @@ module Typhoeus
|
|
69
97
|
sanitized = {:nosignal => true}
|
70
98
|
request.options.each do |k,v|
|
71
99
|
s = k.to_sym
|
72
|
-
next if
|
73
|
-
if new_option =
|
100
|
+
next if SANITIZE_IGNORE.include?(s)
|
101
|
+
if new_option = RENAMED_OPTIONS[k.to_sym]
|
74
102
|
warn("Deprecated option #{k}. Please use #{new_option} instead.")
|
75
103
|
sanitized[new_option] = v
|
76
104
|
# sanitize timeouts
|
77
|
-
elsif
|
105
|
+
elsif SANITIZE_TIMEOUT.include?(s)
|
78
106
|
if !v.integer?
|
79
107
|
warn("Value '#{v}' for option '#{k}' must be integer.")
|
80
108
|
end
|
@@ -134,41 +162,10 @@ module Typhoeus
|
|
134
162
|
end
|
135
163
|
end
|
136
164
|
|
137
|
-
def renamed_options
|
138
|
-
{
|
139
|
-
:auth_method => :httpauth,
|
140
|
-
:connect_timeout => :connecttimeout,
|
141
|
-
:encoding => :accept_encoding,
|
142
|
-
:follow_location => :followlocation,
|
143
|
-
:max_redirects => :maxredirs,
|
144
|
-
:proxy_type => :proxytype,
|
145
|
-
:ssl_cacert => :cainfo,
|
146
|
-
:ssl_capath => :capath,
|
147
|
-
:ssl_cert => :sslcert,
|
148
|
-
:ssl_cert_type => :sslcerttype,
|
149
|
-
:ssl_key => :sslkey,
|
150
|
-
:ssl_key_password => :keypasswd,
|
151
|
-
:ssl_key_type => :sslkeytype,
|
152
|
-
:ssl_version => :sslversion,
|
153
|
-
}
|
154
|
-
end
|
155
|
-
|
156
|
-
def changed_options
|
157
|
-
{
|
158
|
-
:disable_ssl_host_verification => :ssl_verifyhost,
|
159
|
-
:disable_ssl_peer_verification => :ssl_verifypeer,
|
160
|
-
:proxy_auth_method => :proxyauth,
|
161
|
-
}
|
162
|
-
end
|
163
|
-
|
164
|
-
def removed_options
|
165
|
-
[:cache_key_basis, :cache_timeout, :user_agent]
|
166
|
-
end
|
167
|
-
|
168
165
|
def provide_help(option)
|
169
|
-
if new_option =
|
166
|
+
if new_option = CHANGED_OPTIONS[option.to_sym]
|
170
167
|
"\nPlease try #{new_option} instead of #{option}." if new_option
|
171
|
-
elsif
|
168
|
+
elsif REMOVED_OPTIONS.include?(option.to_sym)
|
172
169
|
"\nThe option #{option} was removed."
|
173
170
|
end
|
174
171
|
end
|
data/lib/typhoeus/expectation.rb
CHANGED
@@ -137,7 +137,7 @@ module Typhoeus
|
|
137
137
|
# @return [ void ]
|
138
138
|
def and_return(response=nil, &block)
|
139
139
|
new_response = (response.nil? ? block : response)
|
140
|
-
responses.push
|
140
|
+
responses.push(*new_response)
|
141
141
|
end
|
142
142
|
|
143
143
|
# Checks whether this expectation matches
|
data/lib/typhoeus/hydra.rb
CHANGED
@@ -88,7 +88,7 @@ module Typhoeus
|
|
88
88
|
# Ethon::Multi#initialize
|
89
89
|
def initialize(options = {})
|
90
90
|
@options = options
|
91
|
-
@max_concurrency = @options.fetch(:max_concurrency, 200)
|
91
|
+
@max_concurrency = Integer(@options.fetch(:max_concurrency, 200))
|
92
92
|
@multi = Ethon::Multi.new(options.reject{|k,_| k==:max_concurrency})
|
93
93
|
end
|
94
94
|
end
|
data/lib/typhoeus/request.rb
CHANGED
@@ -211,13 +211,9 @@ module Typhoeus
|
|
211
211
|
def set_defaults
|
212
212
|
default_user_agent = Config.user_agent || Typhoeus::USER_AGENT
|
213
213
|
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
@options[:headers] = {'User-Agent' => default_user_agent}
|
218
|
-
end
|
219
|
-
@options[:verbose] = Typhoeus::Config.verbose if @options[:verbose].nil? && !Typhoeus::Config.verbose.nil?
|
220
|
-
@options[:maxredirs] ||= 50
|
214
|
+
options[:headers] = {'User-Agent' => default_user_agent}.merge(options[:headers] || {})
|
215
|
+
options[:verbose] = Typhoeus::Config.verbose if options[:verbose].nil? && !Typhoeus::Config.verbose.nil?
|
216
|
+
options[:maxredirs] ||= 50
|
221
217
|
end
|
222
218
|
end
|
223
219
|
end
|
@@ -32,7 +32,7 @@ module Typhoeus
|
|
32
32
|
end
|
33
33
|
when String
|
34
34
|
raw.lines.each do |header|
|
35
|
-
next if header.empty? || header
|
35
|
+
next if header.empty? || header.start_with?( 'HTTP/1.' )
|
36
36
|
process_line(header)
|
37
37
|
end
|
38
38
|
end
|
@@ -44,8 +44,8 @@ module Typhoeus
|
|
44
44
|
#
|
45
45
|
# @return [ void ]
|
46
46
|
def process_line(header)
|
47
|
-
key, value = header.split(':', 2)
|
48
|
-
process_pair(key, value)
|
47
|
+
key, value = header.split(':', 2)
|
48
|
+
process_pair(key.strip, value.strip)
|
49
49
|
end
|
50
50
|
|
51
51
|
# Sets key value pair for self and @sanitized.
|
@@ -53,16 +53,20 @@ module Typhoeus
|
|
53
53
|
# @return [ void ]
|
54
54
|
def process_pair(key, value)
|
55
55
|
set_value(key, value, self)
|
56
|
-
|
56
|
+
@sanitized[key.downcase] = self[key]
|
57
57
|
end
|
58
58
|
|
59
59
|
# Sets value for key in specified hash
|
60
60
|
#
|
61
61
|
# @return [ void ]
|
62
62
|
def set_value(key, value, hash)
|
63
|
-
|
64
|
-
|
65
|
-
|
63
|
+
current_value = hash[key]
|
64
|
+
if current_value
|
65
|
+
if current_value.is_a? Array
|
66
|
+
current_value << value
|
67
|
+
else
|
68
|
+
hash[key] = [current_value, value]
|
69
|
+
end
|
66
70
|
else
|
67
71
|
hash[key] = value
|
68
72
|
end
|
@@ -59,14 +59,14 @@ module Typhoeus
|
|
59
59
|
(mock || return_code == :ok) && response_code && response_code != 304
|
60
60
|
end
|
61
61
|
|
62
|
-
# Return
|
62
|
+
# Return whether the response is timed out.
|
63
63
|
#
|
64
64
|
# @example Return if the response timed out.
|
65
65
|
# response.timed_out?
|
66
66
|
#
|
67
67
|
# @return [ Boolean ] Return true if timed out, false else.
|
68
68
|
def timed_out?
|
69
|
-
|
69
|
+
return_code == :operation_timedout
|
70
70
|
end
|
71
71
|
|
72
72
|
private
|
data/lib/typhoeus/version.rb
CHANGED
@@ -83,6 +83,16 @@ describe Typhoeus::Hydra::Queueable do
|
|
83
83
|
hydra.dequeue_many
|
84
84
|
end
|
85
85
|
end
|
86
|
+
|
87
|
+
context "when max_concurrency is a string" do
|
88
|
+
let(:options) { {:max_concurrency => "2"} }
|
89
|
+
it "adds requests from queue to multi" do
|
90
|
+
expect(hydra).to receive(:add).with(first)
|
91
|
+
expect(hydra).to receive(:add).with(second)
|
92
|
+
expect(hydra).to_not receive(:add).with(third)
|
93
|
+
hydra.dequeue_many
|
94
|
+
end
|
95
|
+
end
|
86
96
|
end
|
87
97
|
end
|
88
98
|
end
|
@@ -12,22 +12,6 @@ describe Typhoeus::Response::Status do
|
|
12
12
|
expect(response).to be_timed_out
|
13
13
|
end
|
14
14
|
end
|
15
|
-
|
16
|
-
context "when return code is couldnt_connect" do
|
17
|
-
let(:options) { {:return_code => :couldnt_connect} }
|
18
|
-
|
19
|
-
it "return true" do
|
20
|
-
expect(response).to be_timed_out
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
context "when return code is not operation_timedout or couldnt_connect" do
|
25
|
-
let(:options) { {:return_code => 14} }
|
26
|
-
|
27
|
-
it "returns false" do
|
28
|
-
expect(response).to_not be_timed_out
|
29
|
-
end
|
30
|
-
end
|
31
15
|
end
|
32
16
|
|
33
17
|
describe "#status_message" do
|
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: 0.
|
4
|
+
version: 1.0.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: 2016-01-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: ethon
|