Add configurable HTTP client factory #139
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR refactors the
Http
class to remove its persistentHTTP::Client
usage and instead delegate the creation of HTTP clients to a new factory interface (HttpClientFactory
). By doing so, each request can optionally acquire a client from a custom provide.What Changed
@client
field inHttp
:Http
stored oneHTTP::Client
instance and reused it for all requests.Http
does not store any long-lived client. Instead, it calls a factory’s#acquire_client
method on every request.HttpClientFactory
andDefaultHttpClientFactory
:HttpClientFactory
is an abstract class with three key methods:#acquire_client(endpoint, signer)
– returns a fully configuredHTTP::Client
.#acquire_raw_client(endpoint, signer)
– returns a plainHTTP::Client
, must be implemented by developer.#release(client)
– allows returning or cleaning up the client. (Default implementation is no-op.)DefaultHttpClientFactory
provides the current “create a new client each time” logic, so no immediate behavioral change occurs unless users swap in a different factory.acquire_client
to get a ready-to-use client.release(client)
to allow the factory to clean up or recycle resources.How the New Mechanism Works
#exec
method sends the HTTP request using the acquired client.@factory.release(client)
is called, allowing the factory to decide whether to close, reuse, or discard the client.Closes #77