Skip to content

Conversation

@lauzadis
Copy link
Contributor

@lauzadis lauzadis commented Oct 9, 2025

Adds a new constructor to OkHttpEngine which allows users to bring their own client, allowing them to customize behavior outside of what the SDK exposes.

Issue #

Closes aws/aws-sdk-kotlin#1707

Description of changes

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@lauzadis lauzadis requested a review from a team as a code owner October 9, 2025 09:27
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

1 similar comment
@github-actions
Copy link

github-actions bot commented Oct 9, 2025

Affected Artifacts

Changed in size
Artifact Pull Request (bytes) Latest Release (bytes) Delta (bytes) Delta (percentage)
http-client-engine-okhttp-jvm.jar 123,272 122,918 354 0.29%

@lauzadis lauzadis changed the title feat: add executorService configuration to OkHttpEngine feat: OkHttpEngine BYOC Oct 22, 2025
Comment on lines 41 to 61
public constructor(client: OkHttpClient) : this(OkHttpEngineConfig.Default) {
this.manageClient = false

// destroy our client
this.client.apply {
connectionPool.evictAll()
dispatcher.executorService.shutdown()
}

// use the user-provided client, configured with metrics collection
this.client = client.newBuilder().apply {
eventListenerFactory { call ->
EventListenerChain(
listOf(
HttpEngineEventListener(client.connectionPool, config.hostResolver, client.dispatcher, metrics, call),
),
)
}
addInterceptor(MetricsInterceptor)
}.build()
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correctness: We shouldn't create an OkHttp client just to close it and replace it with the user's client. Let's refactor these constructors to avoid unnecessary client creation and to remove the need for var fields.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

refactored to initialize the client lazily. I think we still need one var since we can't edit the primary constructor

Comment on lines 143 to 145

// configureIosSimulatorTasks()
configureIosSimulatorTasks()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: Why did this change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why it was commented, but I don't think it should be. This is necessary for TLS tests to pass, it was originally added to aws-crt-kotlin and I applied it here too, but it might not be necessary since our CI has been passing without it. Want me to delete it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not necessary for CI and we don't need it for any other reason then yes, I think we should remove it.

@lauzadis lauzadis requested a review from ianbotsf October 22, 2025 22:33
Comment on lines 143 to 145

// configureIosSimulatorTasks()
configureIosSimulatorTasks()

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it's not necessary for CI and we don't need it for any other reason then yes, I think we should remove it.

Comment on lines 43 to 47
private var userProvidedClient: OkHttpClient? = null
public constructor(client: OkHttpClient) : this(OkHttpEngineConfig.Default) {
userProvidedClient = client
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment: The refactor looks much better and addresses my main concern about unnecessary client instantiation. Thanks!

Nit:

we can't edit the primary constructor

I don't believe a constructor's "primaryness" affects the public API. It's a source code term which indicates it's the one that appears on the class declaration line, as opposed to those which appear in the body. The compiler also enforces that if a primary constructor exists then all secondary constructors must invoke it.

I believe this code could be further improved by moving the existing primary constructor to a secondary one and either a) making each secondary constructor fully set the initial state or b) adding a new private primary constructor to set state. As I noted above, my primary concern is addressed so I'll leave it up to you whether to continue iterating.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactored a bit more for option b), what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@lauzadis lauzadis requested a review from ianbotsf October 23, 2025 20:17
@lauzadis lauzadis merged commit 85ad8a0 into main Oct 23, 2025
23 checks passed
@lauzadis lauzadis deleted the configure-executorService branch October 23, 2025 21:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Integrate Support for OkHttp5 engine

3 participants