Skip to content

Conversation

@yschimke
Copy link
Collaborator

@yschimke yschimke commented Aug 12, 2025

@yschimke yschimke changed the title [Not to land] Testing HttpEngine with Call Decorator [Not to land] Testing Android HttpEngine with Call Decorator Aug 13, 2025
*
* A Decorator that changes the OkHttpClient should typically retain later decorators in the new client.
*/
fun interface Decorator {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is adding a brand new public abstraction just for this really worth it? It seems more straightforward to add cancellation support to interceptors (#7164), and treat the HttpEngine interceptor as a "special snowflake" in RealCall. Arguably this wouldn't be as clean as RealCall would need to be aware of HttpEngineInterceptor's existence, but it's not like your approach is squeaky clean either, given you have to refer to OkHttp internals in HttpEngineDecorator (e.g. manually calling BridgeInterceptor which is an internal class). Since neither approach achieves perfect decoupling between the HttpEngine bridge and OkHttp internals, I'd be inclined to go for the most straightforward one.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It exists for other reasons, and is just the best way to express this problem. Call.Factory could be similar, but isn't well adopted. I fear we lost that argument.

#8376
#8800

manually calling BridgeInterceptor which is an internal class

Yep, we should fix this, and have a clean set of APIs for bridging interceptors like Cronet

I'd be inclined to go for the most straightforward one.

I don't think we would do that if it meant treating HttpEngine as a special snowflake in RealCall.


@SuppressSignatureCheck
class HttpEngineCallDecorator(
internal val httpEngine: HttpEngine,
Copy link
Contributor

Choose a reason for hiding this comment

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

It is debatable whether this should use HttpEngine directly, or if it should use the Cronet API wrapper (which would then call HttpEngine). The Cronet API wrapper is more flexible and would make it possible to use other variants of Cronet (such as embedded of Play Services) if we ever want to, but the downside is it would involve OkHttp taking a new dependency on the (very small) cronet-api Maven package.

Copy link
Collaborator Author

@yschimke yschimke Sep 23, 2025

Choose a reason for hiding this comment

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

I think that dependency is the blocker here.

But also, a first version of this should probably be a v2.0 of the google/cronet-transport-for-okhttp

So that can do whatever makes sense?


@SuppressSignatureCheck
class HttpEngineCallDecorator(
internal val httpEngine: HttpEngine,
Copy link
Contributor

Choose a reason for hiding this comment

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

It is debatable whether we want to let the user choose which HttpEngine to use. Arguably this code should instantiate HttpEngine and should configure it by interpreting OkHttpClient settings. Otherwise we may end up backing ourselves into a corner by providing too much flexibility to the user.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep, I'm not aware of what we expect an app developer to configure in typical cases?

Do we want them to allowlist their known hosts for HTTP/3?

But no objection from me. Your call.

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.

2 participants