title: Extending OkHttp protocol selection
body: <p>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).</p>
  
  <p>OkHttp3 only seems to support HTTP/2 Prior Knowledge when using TCP, so I built a custom <code>SSLSocketFactory</code> and <code>SSLSocket</code> 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 <a href="https://github.com/square/okhttp/blob/master/okhttp/src/main/java/okhttp3/internal/connection/RealConnection.java#L286" rel="nofollow noreferrer">is platform-dependent</a>.</p>
  
  <p>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 <code>RealConnection</code> does not look feasible, since okhttp does not provide any sort of <code>ConnectionFactory</code> that you can implement.</p>