feat(java-client): allow caller-supplied OkHttpClient injection - #326
Open
lygaret wants to merge 1 commit into
Open
feat(java-client): allow caller-supplied OkHttpClient injection#326lygaret wants to merge 1 commit into
lygaret wants to merge 1 commit into
Conversation
adds a backwards-compatible `Builder.httpClient(OkHttpClient)` method: when set, the `OkHttp` client used downstream is derived from the caller's; otherwise, the existing default client is built. when a client is provided: - `timeout` setting is ignored - don't close on '#close()', the library doesn't own it in both cases - the `User-Agent`/`X-Client-Version` interceptor is added additionally, expose okhttp as `api` (not `implementation`) so consumers can build their own OkHttpClient against the same okhttp version the client uses. tests: - caller supplied interceptor reaches the server - user-agent/x-client-version remain with custom client - user-agent/x-client-version remain with default client - close() leaves the caller supplied client usable
Collaborator
|
Awesome. Looks good to me, @lygaret! I'll run CI and merge if everything passes. |
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.
adds a backwards-compatible
Builder.httpClient(OkHttpClient)method: when set, theOkHttpclient used downstream is derived from the caller's; otherwise, the existing default client is built.when a client is provided:
timeoutsetting is ignoredin both cases
User-Agent/X-Client-Versioninterceptor is addedadditionally, expose okhttp as
api(notimplementation) so consumers can build their own OkHttpClient against the same okhttp version the client uses.tests:
Note
Low Risk
Backward-compatible builder extension and dependency visibility change; lifecycle fix reduces risk of breaking shared OkHttp pools on close.
Overview
Adds optional
Builder.httpClient(OkHttpClient)so integrators can reuse a shared OkHttp instance (custom interceptors, connection pooling, TLS). When set, the client is built vianewBuilder()on the supplied instance,timeout()is not applied, andclose()no longer shuts down the dispatcher or evicts the pool—the library only tears down HTTP resources for its default-built client.OkHttp is published as an
apidependency so consumers compile against the same OkHttp version as the client. The library still adds itsUser-Agent/X-Client-Versioninterceptor in both paths.Tests cover custom interceptors reaching the wire, default and custom client headers, and that
close()leaves a caller-owned client usable.Reviewed by Cursor Bugbot for commit c137d7e. Bugbot is set up for automated code reviews on this repo. Configure here.