httpx 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 54a10e717268eab1bd790ceb5488f7641814e96f0edc7ff2252d020a73f956d4
4
- data.tar.gz: fac249b2c424c310e8535bdd8940dfeec194b5438e30876da6a3875f349d49ab
3
+ metadata.gz: 1db39d0b49e7ad0f70dabb1190f02f26042b6285119cc8bb9db58b1446faed5a
4
+ data.tar.gz: 53b392efd38a8b2882db5eb348bb988fad88995fb5158fcf8f1556351531e343
5
5
  SHA512:
6
- metadata.gz: 044c55f050be59ec7ef78bde8529b1957d120538c89d1488991b07d87cc60b34c66999861fe48b01719e712dd7ab1f03f349890e4ccc074303788b30798a5a90
7
- data.tar.gz: 0a6b3a24a7d35e7cba39df0b58519b15c15361a96a2e458a1a0bab890a62922ed0cb34881cc506031d8be4a95505444e1401f4570f5d5286372baea548d4b2be
6
+ metadata.gz: f747f05af1955d0ce477dead370b4a037e26179732a93ea04fd679fc019c9d7a0ed503e8d79cc1e276bbd7be594dc6d77bb506ced0144ad9d1f3eecc40497a68
7
+ data.tar.gz: b9d6f55f793f3d9f7cf39957161381642ede2c90aca416f98d26264bb5324f2a774ce7ece3ad67ad194264a16a9a2dc65eeada8d4c41d49566b965a45cd8dc3b
@@ -28,13 +28,20 @@ module HTTPX
28
28
  branch(default_options).wrap(&blk)
29
29
  end
30
30
 
31
- def plugin(*plugins)
31
+ def plugin(*args, **opts)
32
32
  klass = is_a?(Session) ? self.class : Session
33
33
  klass = Class.new(klass)
34
34
  klass.instance_variable_set(:@default_options, klass.default_options.merge(default_options))
35
- klass.plugins(plugins).new
35
+ klass.plugin(*args, **opts).new
36
+ end
37
+
38
+ # deprecated
39
+ def plugins(*args, **opts)
40
+ klass = is_a?(Session) ? self.class : Session
41
+ klass = Class.new(klass)
42
+ klass.instance_variable_set(:@default_options, klass.default_options.merge(default_options))
43
+ klass.plugins(*args, **opts).new
36
44
  end
37
- alias_method :plugins, :plugin
38
45
 
39
46
  def with(options, &blk)
40
47
  branch(default_options.merge(options), &blk)
@@ -54,14 +54,6 @@ module HTTPX
54
54
  handle(request)
55
55
  end
56
56
 
57
- def reenqueue!
58
- requests = @requests.dup
59
- @requests.clear
60
- requests.each do |request|
61
- send(request)
62
- end
63
- end
64
-
65
57
  def consume
66
58
  @requests.each do |request|
67
59
  handle(request)
@@ -54,15 +54,6 @@ module HTTPX
54
54
  true
55
55
  end
56
56
 
57
- def reenqueue!
58
- requests = @streams.keys
59
- @streams.clear
60
- init_connection
61
- requests.each do |request|
62
- send(request)
63
- end
64
- end
65
-
66
57
  def consume
67
58
  @streams.each do |request, stream|
68
59
  handle(request, stream)
@@ -134,6 +134,12 @@ module HTTPX
134
134
  end
135
135
  response
136
136
  end
137
+
138
+ def build_altsvc_connection(_, _, _, _, options)
139
+ return if options.proxy
140
+
141
+ super
142
+ end
137
143
  end
138
144
 
139
145
  module ConnectionMethods
@@ -25,6 +25,17 @@ module HTTPX
25
25
 
26
26
  def self.extra_options(options)
27
27
  Class.new(options.class) do
28
+ # number of seconds after which one can retry the request
29
+ def_option(:retry_after) do |num|
30
+ # return early if callable
31
+ return num if num.respond_to?(:call)
32
+
33
+ num = Integer(num)
34
+ raise Error, ":retry_after must be positive" unless num.positive?
35
+
36
+ num
37
+ end
38
+
28
39
  def_option(:max_retries) do |num|
29
40
  num = Integer(num)
30
41
  raise Error, ":max_retries must be positive" unless num.positive?
@@ -33,6 +44,12 @@ module HTTPX
33
44
  end
34
45
 
35
46
  def_option(:retry_change_requests)
47
+
48
+ def_option(:retry_on) do |callback|
49
+ raise ":retry_on must be called with the response" unless callback.respond_to?(:call) && callback.method(:call).arity == 1
50
+
51
+ callback
52
+ end
36
53
  end.new(options).merge(max_retries: MAX_RETRIES)
37
54
  end
38
55
 
@@ -45,16 +62,19 @@ module HTTPX
45
62
 
46
63
  def fetch_response(request, connections, options)
47
64
  response = super
65
+
66
+ retry_on = options.retry_on
67
+
48
68
  if response.is_a?(ErrorResponse) &&
49
69
  request.retries.positive? &&
50
70
  __repeatable_request?(request, options) &&
51
- __retryable_error?(response.error)
71
+ __retryable_error?(response.error) &&
72
+ (!retry_on || retry_on.call(response))
52
73
  request.retries -= 1
53
74
  log { "failed to get response, #{request.retries} tries to go..." }
54
75
  request.transition(:idle)
55
76
  connection = find_connection(request, connections, options)
56
- connection.send(request)
57
- set_request_timeout(connection, request, options)
77
+ __retry_request(connection, request, options)
58
78
  return
59
79
  end
60
80
  response
@@ -67,6 +87,23 @@ module HTTPX
67
87
  def __retryable_error?(ex)
68
88
  RETRYABLE_ERRORS.any? { |klass| ex.is_a?(klass) }
69
89
  end
90
+
91
+ def __retry_request(connection, request, options)
92
+ retry_after = options.retry_after
93
+ unless retry_after
94
+ connection.send(request)
95
+ set_request_timeout(connection, request, options)
96
+ return
97
+ end
98
+
99
+ retry_after = retry_after.call(request) if retry_after.respond_to?(:call)
100
+ log { "retrying after #{retry_after} secs..." }
101
+ pool.after(retry_after) do
102
+ log { "retrying!!" }
103
+ connection.send(request)
104
+ set_request_timeout(connection, request, options)
105
+ end
106
+ end
70
107
  end
71
108
 
72
109
  module RequestMethods
@@ -172,14 +172,15 @@ module HTTPX
172
172
  def build_request(hostname, type)
173
173
  uri = @uri.dup
174
174
  rklass = @options.request_class
175
+ payload = Resolver.encode_dns_query(hostname, type: RECORD_TYPES[type])
176
+
175
177
  if @resolver_options.use_get
176
178
  params = URI.decode_www_form(uri.query.to_s)
177
179
  params << ["type", type]
178
- params << ["name", CGI.escape(hostname)]
180
+ params << ["dns", Base64.urlsafe_encode64(payload, padding: false)]
179
181
  uri.query = URI.encode_www_form(params)
180
182
  request = rklass.new("GET", uri, @options)
181
183
  else
182
- payload = Resolver.encode_dns_query(hostname, type: RECORD_TYPES[type])
183
184
  request = rklass.new("POST", uri, @options.merge(body: [payload]))
184
185
  request.headers["content-type"] = "application/dns-message"
185
186
  end
@@ -251,12 +251,15 @@ module HTTPX
251
251
  self
252
252
  end
253
253
 
254
+ # :nocov:
254
255
  def plugins(pls)
256
+ warn ":#{__method__} is deprecated, use :plugin instead"
255
257
  pls.each do |pl, *args|
256
258
  plugin(pl, *args)
257
259
  end
258
260
  self
259
261
  end
262
+ # :nocov:
260
263
  end
261
264
 
262
265
  plugin(:proxy) unless ENV.grep(/https?_proxy$/i).empty?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTTPX
4
- VERSION = "0.6.5"
4
+ VERSION = "0.6.6"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httpx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.5
4
+ version: 0.6.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tiago Cardoso
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-08 00:00:00.000000000 Z
11
+ date: 2020-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: http-2-next