async-http-faraday 0.20.0 → 0.21.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
  SHA256:
3
- metadata.gz: c35355716bc9483c9f0dcd3070e31cfa0570e49e20d25f96fa429c06d55fef5f
4
- data.tar.gz: 8781699d3bef67478a25bee464f7ccd9bb7cfcf39dae30879f7ad2c09b767e9b
3
+ metadata.gz: 61ec5bb845598b4ed1282944e5ecce5ed41fd0abcac72c4bcdaedcf40b707e89
4
+ data.tar.gz: b16fe2a762a49b3cc20cc5c8f7e674d764ef81f1ab1cd8f95fa41f11e5bc057e
5
5
  SHA512:
6
- metadata.gz: 785d20de694024d75fd214bdfbf0680d7de1e0cb8fb695434186b51c829b2b04c9c957a6cab120ce64b75b7daa57c9fa26cd19940e22296015183793ec2bbac3
7
- data.tar.gz: 4f3cf8059b823e6db1b2be08eb76cd49d8383deb1685e8bafb31796d8c23a0f67672062c6739097a71dd944f48e346c74b9ca1c01a34ebbf0736c39fe049bebc
6
+ metadata.gz: 330032d445badaf1eace0bf580012c573b24a83128c3cb7bd6b479d8710b65558450d892000cbf21aacda704428d28e63dba834f7456c5bc53b7c473f6cd511b
7
+ data.tar.gz: 584dd4a49d4af9d088a386f8a6130f199396ba6b93ee79af3a9fc15a6ebfcf66f0cddc7d95cfabb1d9d9acc18291e2128b0e003845e7c6241ec1fc7cc3ba2d2a
checksums.yaml.gz.sig CHANGED
Binary file
data/examples/topics.rb CHANGED
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  # Released under the MIT License.
5
- # Copyright, 2020-2024, by Samuel Williams.
5
+ # Copyright, 2020-2025, by Samuel Williams.
6
6
 
7
7
  $LOAD_PATH.unshift File.expand_path("../lib", __dir__)
8
8
 
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2024, by Samuel Williams.
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 => e
207
- raise ::Faraday::TimeoutError, e
208
- rescue OpenSSL::SSL::SSLError => e
209
- raise ::Faraday::SSLError, e
210
- rescue *CONNECTION_EXCEPTIONS => e
211
- raise ::Faraday::ConnectionFailed, e
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 @timeout
234
- task.with_timeout(@timeout, ::Faraday::TimeoutError) do
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 +"" if body.nil?
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,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2024, by Samuel Williams.
4
+ # Copyright, 2024-2025, by Samuel Williams.
5
5
 
6
6
  require "faraday"
7
7
  require "faraday/adapter"
@@ -1,9 +1,9 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2020-2024, by Samuel Williams.
4
+ # Copyright, 2020-2025, by Samuel Williams.
5
5
 
6
- require_relative "adapter"
6
+ require_relative "register"
7
7
 
8
8
  # Set the default adapter to use Async::HTTP.
9
9
  ::Faraday.default_adapter = :async_http
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2025, by Samuel Williams.
5
+
6
+ require_relative "adapter"
7
+
8
+ Faraday::Adapter.register_middleware :async_http => Async::HTTP::Faraday::Adapter
@@ -1,12 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2024, by Samuel Williams.
4
+ # Copyright, 2018-2025, by Samuel Williams.
5
5
 
6
6
  module Async
7
7
  module HTTP
8
8
  module Faraday
9
- VERSION = "0.20.0"
9
+ VERSION = "0.21.0"
10
10
  end
11
11
  end
12
12
  end
@@ -1,12 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  # Released under the MIT License.
4
- # Copyright, 2018-2024, by Samuel Williams.
4
+ # Copyright, 2018-2025, by Samuel Williams.
5
5
 
6
6
  require_relative "faraday/version"
7
- require_relative "faraday/adapter"
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`](https://socketry.github.io/async-http-faraday/releases/index#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
- - [Config Block](https://socketry.github.io/async-http-faraday/releases/index#config-block)
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
- - [Per-thread Client Cache](https://socketry.github.io/async-http-faraday/releases/index#per-thread-client-cache)
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
- ### Config Block
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
- ### Per-thread Client Cache
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.20.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-01-23 00:00:00.000000000 Z
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