yawkat
yawkat

Reputation: 382

Extending OkHttp protocol selection

I am trying to implement a client for a HTTP/2-based protocol using OkHttp. The protocol is basically an unencrypted HTTP/2-Prior-Knowledge stream over a custom TCP protocol (yes, I know it's broken, no, I can't change it).

OkHttp3 only seems to support HTTP/2 Prior Knowledge when using TCP, so I built a custom SSLSocketFactory and SSLSocket that implement my protocol. This is hacky but works alright until the prior knowledge requirement kicks in. My remote does not support HTTP/1.1->HTTP/2 upgrade, it requires prior knowledge, which OkHttp only seems to support via TLS extensions, but the protocol selection code is platform-dependent.

Is there any way to hook into the protocol selection logic that does not involve reimplementing half of OkHttp or reflecting into OkHttp- or JDK-internal classes? Maybe even without the fake-TLS hack? Replacing RealConnection does not look feasible, since okhttp does not provide any sort of ConnectionFactory that you can implement.

Upvotes: 2

Views: 403

Answers (1)

Jesse Wilson
Jesse Wilson

Reputation: 40585

OkHttp will only do HTTP/2 over HTTPS with ALPN. Since you’re stuck with your own custom protocol, consider adding an HTTP/2 over HTTPS server that sits in front of your custom protocol. You might be able to do this with nginx?

Upvotes: 1

Related Questions