httpx 0.6.5 → 0.6.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/httpx/chainable.rb +10 -3
- data/lib/httpx/connection/http1.rb +0 -8
- data/lib/httpx/connection/http2.rb +0 -9
- data/lib/httpx/plugins/proxy.rb +6 -0
- data/lib/httpx/plugins/retries.rb +40 -3
- data/lib/httpx/resolver/https.rb +3 -2
- data/lib/httpx/session.rb +3 -0
- data/lib/httpx/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1db39d0b49e7ad0f70dabb1190f02f26042b6285119cc8bb9db58b1446faed5a
|
4
|
+
data.tar.gz: 53b392efd38a8b2882db5eb348bb988fad88995fb5158fcf8f1556351531e343
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f747f05af1955d0ce477dead370b4a037e26179732a93ea04fd679fc019c9d7a0ed503e8d79cc1e276bbd7be594dc6d77bb506ced0144ad9d1f3eecc40497a68
|
7
|
+
data.tar.gz: b9d6f55f793f3d9f7cf39957161381642ede2c90aca416f98d26264bb5324f2a774ce7ece3ad67ad194264a16a9a2dc65eeada8d4c41d49566b965a45cd8dc3b
|
data/lib/httpx/chainable.rb
CHANGED
@@ -28,13 +28,20 @@ module HTTPX
|
|
28
28
|
branch(default_options).wrap(&blk)
|
29
29
|
end
|
30
30
|
|
31
|
-
def plugin(*
|
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.
|
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,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)
|
data/lib/httpx/plugins/proxy.rb
CHANGED
@@ -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
|
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
|
data/lib/httpx/resolver/https.rb
CHANGED
@@ -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 << ["
|
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
|
data/lib/httpx/session.rb
CHANGED
@@ -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?
|
data/lib/httpx/version.rb
CHANGED
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.
|
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-
|
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
|