client: WithHTTPClient and WithTransport options#25
Merged
Conversation
Two new Option constructors so callers can plug their own HTTP client or transport without mutating fields after NewClient returns. WithHTTPClient swaps in a caller-supplied *http.Client. Useful when the application already maintains a shared connection pool with mTLS config or auth-injecting transport that the existing WithTimeout / WithMaxRetries options can't express. WithTransport replaces the underlying http.RoundTripper while preserving the Client's other settings (timeout, cookie jar, ...). Useful for stacking middleware — auth headers, request logging, external retry, rate-limit — without rewriting the default Client. Both options compose with each other and with WithUserAgent, WithTimeout, WithMaxRetries, and WithRateLimiter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
Two new `Option` constructors for `client.NewClient`:
Both options compose with each other and with the existing `WithUserAgent`, `WithTimeout`, `WithMaxRetries`, `WithRateLimiter`.
Why
Today the field-mutation pattern (`c := client.NewClient(); c.HTTPClient = ...`) works but isn't idiomatic — consumers either know to mutate after construction or copy the `DefaultClient()` shape by hand. The new options follow the existing `Option func(*Client)` pattern so configuration stays declarative in the `NewClient` call site.