async-http-faraday 0.20.0 → 0.21.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/examples/topics.rb +1 -1
- data/lib/async/http/faraday/adapter.rb +20 -13
- data/lib/async/http/faraday/clients.rb +1 -1
- data/lib/async/http/faraday/default.rb +2 -2
- data/lib/async/http/faraday/register.rb +8 -0
- data/lib/async/http/faraday/version.rb +2 -2
- data/lib/async/http/faraday.rb +2 -4
- data/readme.md +7 -3
- data/releases.md +14 -3
- data.tar.gz.sig +0 -0
- metadata +3 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61ec5bb845598b4ed1282944e5ecce5ed41fd0abcac72c4bcdaedcf40b707e89
|
4
|
+
data.tar.gz: b16fe2a762a49b3cc20cc5c8f7e674d764ef81f1ab1cd8f95fa41f11e5bc057e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 330032d445badaf1eace0bf580012c573b24a83128c3cb7bd6b479d8710b65558450d892000cbf21aacda704428d28e63dba834f7456c5bc53b7c473f6cd511b
|
7
|
+
data.tar.gz: 584dd4a49d4af9d088a386f8a6130f199396ba6b93ee79af3a9fc15a6ebfcf66f0cddc7d95cfabb1d9d9acc18291e2128b0e003845e7c6241ec1fc7cc3ba2d2a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/examples/topics.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2018-
|
4
|
+
# Copyright, 2018-2025, by Samuel Williams.
|
5
5
|
# Copyright, 2018, by Andreas Garnaes.
|
6
6
|
# Copyright, 2019, by Denis Talakevich.
|
7
7
|
# Copyright, 2019-2020, by Igor Sidorov.
|
@@ -119,6 +119,7 @@ module Async
|
|
119
119
|
super
|
120
120
|
|
121
121
|
@timeout = @connection_options.delete(:timeout)
|
122
|
+
@read_timeout = @connection_options.delete(:read_timeout)
|
122
123
|
|
123
124
|
if clients = @connection_options.delete(:clients)
|
124
125
|
@clients = clients.call(**@connection_options, &@config_block)
|
@@ -127,6 +128,12 @@ module Async
|
|
127
128
|
end
|
128
129
|
end
|
129
130
|
|
131
|
+
# @attribute [Numeric | Nil] The maximum time to send a request and wait for a response.
|
132
|
+
attr :timeout
|
133
|
+
|
134
|
+
# @attribute [Numeric | Nil] The maximum time to wait for an individual IO operation.
|
135
|
+
attr :read_timeout
|
136
|
+
|
130
137
|
# Close all clients.
|
131
138
|
def close
|
132
139
|
# The order of operations here is to avoid a race condition between iterating over clients (#close may yield) and creating new clients.
|
@@ -181,7 +188,7 @@ module Async
|
|
181
188
|
|
182
189
|
request = ::Protocol::HTTP::Request.new(endpoint.scheme, endpoint.authority, method, endpoint.path, nil, headers, body)
|
183
190
|
|
184
|
-
with_timeout do
|
191
|
+
with_timeout(env.request.timeout || @timeout) do
|
185
192
|
if env.stream_response?
|
186
193
|
response = env.stream_response do |&on_data|
|
187
194
|
response = client.call(request)
|
@@ -203,17 +210,17 @@ module Async
|
|
203
210
|
end
|
204
211
|
|
205
212
|
return @app.call(env)
|
206
|
-
rescue Errno::ETIMEDOUT, Async::TimeoutError =>
|
207
|
-
raise ::Faraday::TimeoutError,
|
208
|
-
rescue OpenSSL::SSL::SSLError =>
|
209
|
-
raise ::Faraday::SSLError,
|
210
|
-
rescue *CONNECTION_EXCEPTIONS =>
|
211
|
-
raise ::Faraday::ConnectionFailed,
|
213
|
+
rescue Errno::ETIMEDOUT, Async::TimeoutError => error
|
214
|
+
raise ::Faraday::TimeoutError, error
|
215
|
+
rescue OpenSSL::SSL::SSLError => error
|
216
|
+
raise ::Faraday::SSLError, error
|
217
|
+
rescue *CONNECTION_EXCEPTIONS => error
|
218
|
+
raise ::Faraday::ConnectionFailed, error
|
212
219
|
end
|
213
220
|
|
214
221
|
def with_client(env)
|
215
222
|
Sync do
|
216
|
-
endpoint = Endpoint.new(env.url)
|
223
|
+
endpoint = Endpoint.new(env.url, timeout: @read_timeout)
|
217
224
|
|
218
225
|
if proxy = env.request.proxy
|
219
226
|
proxy_endpoint = Endpoint.new(proxy.uri)
|
@@ -229,9 +236,9 @@ module Async
|
|
229
236
|
end
|
230
237
|
end
|
231
238
|
|
232
|
-
def with_timeout(task: Async::Task.current)
|
233
|
-
if
|
234
|
-
task.with_timeout(
|
239
|
+
def with_timeout(timeout = @timeout, task: Async::Task.current)
|
240
|
+
if timeout
|
241
|
+
task.with_timeout(timeout, ::Faraday::TimeoutError) do
|
235
242
|
yield
|
236
243
|
end
|
237
244
|
else
|
@@ -241,7 +248,7 @@ module Async
|
|
241
248
|
|
242
249
|
def encoded_body(response)
|
243
250
|
body = response.read
|
244
|
-
return
|
251
|
+
return "" if body.nil?
|
245
252
|
content_type = response.headers["content-type"]
|
246
253
|
return body unless content_type
|
247
254
|
params = extract_type_parameters(content_type)
|
@@ -1,9 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2020-
|
4
|
+
# Copyright, 2020-2025, by Samuel Williams.
|
5
5
|
|
6
|
-
require_relative "
|
6
|
+
require_relative "register"
|
7
7
|
|
8
8
|
# Set the default adapter to use Async::HTTP.
|
9
9
|
::Faraday.default_adapter = :async_http
|
@@ -1,12 +1,12 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2018-
|
4
|
+
# Copyright, 2018-2025, by Samuel Williams.
|
5
5
|
|
6
6
|
module Async
|
7
7
|
module HTTP
|
8
8
|
module Faraday
|
9
|
-
VERSION = "0.
|
9
|
+
VERSION = "0.21.0"
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
data/lib/async/http/faraday.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
# Released under the MIT License.
|
4
|
-
# Copyright, 2018-
|
4
|
+
# Copyright, 2018-2025, by Samuel Williams.
|
5
5
|
|
6
6
|
require_relative "faraday/version"
|
7
|
-
require_relative "faraday/
|
8
|
-
|
9
|
-
Faraday::Adapter.register_middleware :async_http => Async::HTTP::Faraday::Adapter
|
7
|
+
require_relative "faraday/register"
|
10
8
|
|
11
9
|
# @namespace
|
12
10
|
module Async
|
data/readme.md
CHANGED
@@ -17,6 +17,10 @@ Please see the [project documentation](https://socketry.github.io/async-http-far
|
|
17
17
|
|
18
18
|
Please see the [project releases](https://socketry.github.io/async-http-faraday/releases/index) for all releases.
|
19
19
|
|
20
|
+
### v0.21.0
|
21
|
+
|
22
|
+
- [Improved support for `timeout` and `read_timeout`.](https://socketry.github.io/async-http-faraday/releases/index#improved-support-for-timeout-and-read_timeout.)
|
23
|
+
|
20
24
|
### v0.20.0
|
21
25
|
|
22
26
|
- Implement the new response streaming interface, which provides the initial response status code and headers before streaming the response body.
|
@@ -24,15 +28,15 @@ Please see the [project releases](https://socketry.github.io/async-http-faraday/
|
|
24
28
|
|
25
29
|
### v0.19.0
|
26
30
|
|
27
|
-
- [Support `in_parallel
|
31
|
+
- [Support `in_parallel`.](https://socketry.github.io/async-http-faraday/releases/index#support-in_parallel.)
|
28
32
|
|
29
33
|
### v0.18.0
|
30
34
|
|
31
|
-
- [
|
35
|
+
- [Support for `config_block` returning a middleware wrapper.](https://socketry.github.io/async-http-faraday/releases/index#support-for-config_block-returning-a-middleware-wrapper.)
|
32
36
|
|
33
37
|
### v0.17.0
|
34
38
|
|
35
|
-
- [
|
39
|
+
- [Introduced a per-thread `Client` cache.](https://socketry.github.io/async-http-faraday/releases/index#introduced-a-per-thread-client-cache.)
|
36
40
|
|
37
41
|
## Contributing
|
38
42
|
|
data/releases.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Releases
|
2
2
|
|
3
|
+
## v0.21.0
|
4
|
+
|
5
|
+
### Improved support for `timeout` and `read_timeout`.
|
6
|
+
|
7
|
+
Previously, only a per-connection `timeout` was supported, but now:
|
8
|
+
|
9
|
+
1. `timeout` can be set per request too.
|
10
|
+
2. `read_timeout` can be set per adapter and is assigned to `IO#timeout` if available.
|
11
|
+
|
12
|
+
This improves compatibility with existing code that uses `timeout` and `read_timeout`.
|
13
|
+
|
3
14
|
## v0.20.0
|
4
15
|
|
5
16
|
- Implement the new response streaming interface, which provides the initial response status code and headers before streaming the response body.
|
@@ -7,7 +18,7 @@
|
|
7
18
|
|
8
19
|
## v0.19.0
|
9
20
|
|
10
|
-
### Support `in_parallel
|
21
|
+
### Support `in_parallel`.
|
11
22
|
|
12
23
|
The adapter now supports the `in_parallel` method, which allows multiple requests to be made concurrently.
|
13
24
|
|
@@ -45,7 +56,7 @@ end
|
|
45
56
|
|
46
57
|
## v0.18.0
|
47
58
|
|
48
|
-
###
|
59
|
+
### Support for `config_block` returning a middleware wrapper.
|
49
60
|
|
50
61
|
The `config_block` provided to the adapter must now return `nil`, `client` or a middleware wrapper around `client`.
|
51
62
|
|
@@ -63,7 +74,7 @@ end
|
|
63
74
|
|
64
75
|
## v0.17.0
|
65
76
|
|
66
|
-
###
|
77
|
+
### Introduced a per-thread `Client` cache.
|
67
78
|
|
68
79
|
The default adapter now uses a per-thread client cache internally, to improve compatibility with existing code that shares a single `Faraday::Connection` instance across multiple threads.
|
69
80
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: async-http-faraday
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.21.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samuel Williams
|
@@ -45,7 +45,7 @@ cert_chain:
|
|
45
45
|
Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
|
46
46
|
voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
|
47
47
|
-----END CERTIFICATE-----
|
48
|
-
date: 2025-
|
48
|
+
date: 2025-02-15 00:00:00.000000000 Z
|
49
49
|
dependencies:
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: async-http
|
@@ -84,6 +84,7 @@ files:
|
|
84
84
|
- lib/async/http/faraday/adapter.rb
|
85
85
|
- lib/async/http/faraday/clients.rb
|
86
86
|
- lib/async/http/faraday/default.rb
|
87
|
+
- lib/async/http/faraday/register.rb
|
87
88
|
- lib/async/http/faraday/version.rb
|
88
89
|
- license.md
|
89
90
|
- readme.md
|
metadata.gz.sig
CHANGED
Binary file
|