async-http-faraday 0.21.0 → 0.22.1

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: 61ec5bb845598b4ed1282944e5ecce5ed41fd0abcac72c4bcdaedcf40b707e89
4
- data.tar.gz: b16fe2a762a49b3cc20cc5c8f7e674d764ef81f1ab1cd8f95fa41f11e5bc057e
3
+ metadata.gz: 7d9bc8db7f390b5eab35d03ad3748aebcf800ebbfbf63c47e06345e9bf0ccc7b
4
+ data.tar.gz: eb25b8a2a39b8d62b36dc5f5a80c33576c10496bd63d4e4629e612801704df54
5
5
  SHA512:
6
- metadata.gz: 330032d445badaf1eace0bf580012c573b24a83128c3cb7bd6b479d8710b65558450d892000cbf21aacda704428d28e63dba834f7456c5bc53b7c473f6cd511b
7
- data.tar.gz: 584dd4a49d4af9d088a386f8a6130f199396ba6b93ee79af3a9fc15a6ebfcf66f0cddc7d95cfabb1d9d9acc18291e2128b0e003845e7c6241ec1fc7cc3ba2d2a
6
+ metadata.gz: 9f08eb5f9fd6726f3af04de66b4cb55120e8019ba9171ca171f5c5cb20e768813b95ef0035d297b6281de6c783fd29c7ce74ee0939cea5565ed46e715d827339
7
+ data.tar.gz: c0fd6948d709475a6746f3e3edcba70ca2e71c3dbc1f5b3dfc97097b4ff98cf7d0a2036ae1fdb8f9a815e924f2ed0e808af19b09c63ef10e5f6609171696ef9e
checksums.yaml.gz.sig CHANGED
Binary file
@@ -9,6 +9,7 @@
9
9
  # Copyright, 2023, by Flavio Fernandes.
10
10
  # Copyright, 2024, by Jacob Frautschi.
11
11
  # Copyright, 2025, by Nikolaos Anastopoulos.
12
+ # Copyright, 2025, by Pedro Fayolle.
12
13
 
13
14
  require "faraday"
14
15
  require "faraday/adapter"
@@ -32,11 +33,16 @@ module Async
32
33
  #
33
34
  # @parameter body [Interface(:read)] The input body to wrap.
34
35
  # @parameter block_size [Integer] The size of the blocks to read from the body.
35
- def initialize(body, block_size: 4096)
36
+ # @parameter length [Integer | Nil] The length of the body, if known.
37
+ def initialize(body, length = nil, block_size: 4096)
36
38
  @body = body
39
+ @length = length
37
40
  @block_size = block_size
38
41
  end
39
42
 
43
+ # @attribute [Integer | Nil] The total length of the body, or `nil` if the length is unknown.
44
+ attr :length
45
+
40
46
  # Close the body if possible.
41
47
  def close(error = nil)
42
48
  @body.close if @body.respond_to?(:close)
@@ -111,7 +117,7 @@ module Async
111
117
  SocketError
112
118
  ].freeze
113
119
 
114
- # Create a Farady compatible adapter.
120
+ # Create a Faraday compatible adapter.
115
121
  #
116
122
  # @parameter timeout [Integer] The timeout for requests.
117
123
  # @parameter options [Hash] Additional options to pass to the underlying Async::HTTP::Client.
@@ -168,22 +174,27 @@ module Async
168
174
 
169
175
  def perform_request(env)
170
176
  with_client(env) do |endpoint, client|
177
+ if headers = env.request_headers
178
+ headers = ::Protocol::HTTP::Headers[headers]
179
+
180
+ # Use content-length to inform body length if given, but remove the header since it will be
181
+ # set for us later anyway, and not doing so could result in a duplicate content-length headers
182
+ # if capitalization differs
183
+ content_length = headers.delete("content-length")&.to_i
184
+ end
185
+
171
186
  if body = env.body
172
187
  # We need to ensure the body is wrapped in a Readable object so that it can be read in chunks:
173
188
  # Faraday's body only responds to `#read`.
174
189
  if body.is_a?(::Protocol::HTTP::Body::Readable)
175
190
  # Good to go
176
191
  elsif body.respond_to?(:read)
177
- body = BodyReadWrapper.new(body)
192
+ body = BodyReadWrapper.new(body, content_length)
178
193
  else
179
194
  body = ::Protocol::HTTP::Body::Buffered.wrap(body)
180
195
  end
181
196
  end
182
197
 
183
- if headers = env.request_headers
184
- headers = ::Protocol::HTTP::Headers[headers]
185
- end
186
-
187
198
  method = env.method.to_s.upcase
188
199
 
189
200
  request = ::Protocol::HTTP::Request.new(endpoint.scheme, endpoint.authority, method, endpoint.path, nil, headers, body)
@@ -177,10 +177,10 @@ module Async
177
177
  # This will close all clients associated with all threads.
178
178
  def close
179
179
  Thread.list.each do |thread|
180
- if clients = thread[@key]
181
- clients.close
180
+ if clients = thread.thread_variable_get(@key)
181
+ thread.thread_variable_set(@key, nil)
182
182
 
183
- thread[@key] = nil
183
+ clients.close
184
184
  end
185
185
  end
186
186
  end
@@ -6,7 +6,7 @@
6
6
  module Async
7
7
  module HTTP
8
8
  module Faraday
9
- VERSION = "0.21.0"
9
+ VERSION = "0.22.1"
10
10
  end
11
11
  end
12
12
  end
data/license.md CHANGED
@@ -10,6 +10,7 @@ Copyright, 2023, by Genki Takiuchi.
10
10
  Copyright, 2023, by Flavio Fernandes.
11
11
  Copyright, 2024, by Jacob Frautschi.
12
12
  Copyright, 2025, by Nikolaos Anastopoulos.
13
+ Copyright, 2025, by Pedro Fayolle.
13
14
 
14
15
  Permission is hereby granted, free of charge, to any person obtaining a copy
15
16
  of this software and associated documentation files (the "Software"), to deal
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.22.1
21
+
22
+ - Fix memory leak in `Async::HTTP::Faraday::PerThreadPersistentClients` by ensuring that the `close` method is called on all clients when the adapter is closed.
23
+
20
24
  ### v0.21.0
21
25
 
22
26
  - [Improved support for `timeout` and `read_timeout`.](https://socketry.github.io/async-http-faraday/releases/index#improved-support-for-timeout-and-read_timeout.)
data/releases.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Releases
2
2
 
3
+ ## v0.22.1
4
+
5
+ - Fix memory leak in `Async::HTTP::Faraday::PerThreadPersistentClients` by ensuring that the `close` method is called on all clients when the adapter is closed.
6
+
3
7
  ## v0.21.0
4
8
 
5
9
  ### Improved support for `timeout` and `read_timeout`.
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.21.0
4
+ version: 0.22.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
@@ -14,6 +14,7 @@ authors:
14
14
  - Denis Talakevich
15
15
  - Flavio Fernandes
16
16
  - Jacob Frautschi
17
+ - Pedro Fayolle
17
18
  bindir: bin
18
19
  cert_chain:
19
20
  - |
@@ -45,7 +46,7 @@ cert_chain:
45
46
  Q2K9NVun/S785AP05vKkXZEFYxqG6EW012U4oLcFl5MySFajYXRYbuUpH6AY+HP8
46
47
  voD0MPg1DssDLKwXyt1eKD/+Fq0bFWhwVM/1XiAXL7lyYUyOq24KHgQ2Csg=
47
48
  -----END CERTIFICATE-----
48
- date: 2025-02-15 00:00:00.000000000 Z
49
+ date: 1980-01-02 00:00:00.000000000 Z
49
50
  dependencies:
50
51
  - !ruby/object:Gem::Dependency
51
52
  name: async-http
@@ -103,14 +104,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
103
104
  requirements:
104
105
  - - ">="
105
106
  - !ruby/object:Gem::Version
106
- version: '3.1'
107
+ version: '3.2'
107
108
  required_rubygems_version: !ruby/object:Gem::Requirement
108
109
  requirements:
109
110
  - - ">="
110
111
  - !ruby/object:Gem::Version
111
112
  version: '0'
112
113
  requirements: []
113
- rubygems_version: 3.6.2
114
+ rubygems_version: 3.6.9
114
115
  specification_version: 4
115
116
  summary: Provides an adaptor between async-http and faraday.
116
117
  test_files: []
metadata.gz.sig CHANGED
Binary file