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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d6141d4a4fce3468605180e9fa209f44dcadb297
4
- data.tar.gz: f44b3f1fc22744bee6e552bad735bbeed1acca25
3
+ metadata.gz: d43b52d7dfc8cb4542b1670f07f43351906129ba
4
+ data.tar.gz: 3ff1f2870c76247f16ce94c00e7f534dafe6c879
5
5
  SHA512:
6
- metadata.gz: 22303b457d981211f37f0da3f056d9a78e97be9c907878b9ab3ae497db3f09c0975c1d0b305f30ffd75c308d5fa08ce3aee22314591b0e056cebabd402529195
7
- data.tar.gz: 35ca8ddee5fe6122677ea2823b1c9db407e848e2070dc59f78780d88c56fe5d8cf7d6386fe6e0e8d1f5dde624bfec704aa9dad4d34afd95dde922c8f10a863f5
6
+ metadata.gz: fda1a066fe0e0d0a6c078540d85b87739fe7e24907b92e272dc86d473cc9d6a01bc726047f942efc5a7a1a35da62dcfe2bff10c952469c464174ab1592d1c10c
7
+ data.tar.gz: d407bebd52067ed31b54e4b72a5d5e8ce65f9d43b9fe17e00fd4e7ae024bff905f95ff268e6ca22d2aad90a8fec440c1d69ae9171c83ed68c832831a5699c703
data/.travis.yml CHANGED
@@ -1,4 +1,5 @@
1
1
  script: "bundle exec rake"
2
+ sudo: false
2
3
  rvm:
3
4
  - 1.8.7
4
5
  - 1.9.2
data/CHANGELOG.md CHANGED
@@ -2,7 +2,27 @@
2
2
 
3
3
  ## Master
4
4
 
5
- [Full Changelog](http://github.com/typhoeus/typhoeus/compare/v0.7.3...master)
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
- if parallel?(env)
90
- # TODO: error callback in async mode
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 [:method, :cache_ttl].include?(s)
73
- if new_option = renamed_options[k.to_sym]
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 [:timeout_ms, :connecttimeout_ms].include?(s)
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 = changed_options[option.to_sym]
166
+ if new_option = CHANGED_OPTIONS[option.to_sym]
170
167
  "\nPlease try #{new_option} instead of #{option}." if new_option
171
- elsif removed_options.include?(option.to_sym)
168
+ elsif REMOVED_OPTIONS.include?(option.to_sym)
172
169
  "\nThe option #{option} was removed."
173
170
  end
174
171
  end
@@ -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 *new_response
140
+ responses.push(*new_response)
141
141
  end
142
142
 
143
143
  # Checks whether this expectation matches
@@ -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
@@ -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
- if @options[:headers]
215
- @options[:headers] = {'User-Agent' => default_user_agent}.merge(options[:headers])
216
- else
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
@@ -27,7 +27,7 @@ module Typhoeus
27
27
  #
28
28
  # @return [ Boolean ] True if any on_body blocks have been set.
29
29
  def streaming?
30
- @on_body && @on_body.any?
30
+ defined?(@on_body) && @on_body.any?
31
31
  end
32
32
  end
33
33
  end
@@ -7,7 +7,7 @@ module Typhoeus
7
7
  attr_writer :cached
8
8
 
9
9
  def cached?
10
- !!@cached
10
+ defined?(@cached) ? !!@cached : false
11
11
  end
12
12
  end
13
13
  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 =~ /^HTTP\/1.[01]/
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).map(&:strip)
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
- set_value(key.downcase, value, @sanitized)
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
- if hash.has_key?(key)
64
- hash[key] = [hash[key]] unless hash[key].is_a? Array
65
- hash[key].push(value)
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 wether the response is timed out.
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
- [:operation_timedout, :couldnt_connect].include?(return_code)
69
+ return_code == :operation_timedout
70
70
  end
71
71
 
72
72
  private
@@ -1,5 +1,5 @@
1
1
  module Typhoeus
2
2
 
3
3
  # The current Typhoeus version.
4
- VERSION = '0.8.0'
4
+ VERSION = '1.0.0'
5
5
  end
@@ -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.8.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: 2015-09-17 00:00:00.000000000 Z
13
+ date: 2016-01-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: ethon