-
Notifications
You must be signed in to change notification settings - Fork 9.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OkHttpClient should allow alternative protocols #7272
Comments
Could you provide an example? Generally this isn't a good fit for OkHttp. It tries to be the simple ergonomic http client for typical use cases. But look at this example for an approach to use Unix Domain Sockets https://github.com/square/okhttp/blob/f8fd4d08decf697013008b05ad7d2be10a648358/samples/unixdomainsockets/src/main/java/okhttp3/unixdomainsockets/ClientAndServer.java |
I also tried Apache HttpClient.
The codes look simple. |
The following function blocks me currently.
Certainly, my protocol is not in the above list. So, the IllegalArgumentException must be thrown. |
You can just about get this working by passing in your sslSocketFactory as the socketFactory, and then OkHttp won't know anything about your SSL types. You need a hacky workaround #6561, but it should work ok. We don't expose the implementation details of Platform, and discussed it again recently with the same decision #7238 |
I tried to wrap my SSLSocketFactory with DelegatingSocketFactory mentioned by #6561.
It was really unexpected. |
In this case you would make a "http:" request, but truth be told it's all getting a bit hacky. So maybe this was a bad idea. |
My own SSLContext and SSLSocketFactory work fine with not only Apache HttpClient, but also Eclipse Jetty server and client. |
Maybe we could take a step back and ask what your goal is? Making OkHttp extensible is possible if the use case is compelling! |
I am developing an alternative JSSE provider, which has two goals:
OkHttp works fine for my first goal. Because it recognizes (doesn't block) TLS protocols, even though it doesn't known the new cipher suites. |
I just modified TlsVersion.kt [1] and added my protocol to the SSL/TLS version list as workaround. [1] https://github.com/square/okhttp/blob/parent-4.9.3/okhttp/src/main/kotlin/okhttp3/TlsVersion.kt |
@johnshajiang I think we could give an internal SPI for Platform with an experimental annotation. Basically it wouldn't be guaranteed for stability across versions. But would be enough to do what you need. In truth it looks a lot like Platform.resetForTests and extending Platform yourself. https://github.com/square/okhttp/blob/master/okhttp/src/jvmMain/kotlin/okhttp3/internal/platform/Platform.kt#L188 |
@johnshajiang curious if you looked at the above approach? If it's possible then it's probably the best we can do for this experimental use case, until we see more mainstream requirements to allow other protocols. I'll close this in a week or so, as we probably won't make this public API. |
Sorry, I (as a newbie to OkHttp) don't understand this solution. Just took a look at |
It's in the link from the comment above Platform.resetForTests. But be aware as this isn't public api, it isn't stable, so you shouldn't rely on this not changing. It would be dangerous code to rely on for any library. But fine for experimentation. |
I just figured out how to set a custom Platform, named MyPlatform. Should I need to set a ConnectionSpec like the below?
If do that, the below error still raises,
If not set a ConnectionSpec, another exception is thrown, |
You still won't be able to set a ConnectionSpec with the values you need. I'd leave them as default and then change the Platform methods to configure your socket. That exception comes from
Calling isCompatible here
But this is what you will have to try to work through the methods in Platform, find creative ways to move it forward. Including workarounds/kludges to make it accept your connection. This points to why it's not trivial for us to make this a new public api/feature. And apologies in advance if this turns out to be a dead end, I was hoping to give you a way forward, but haven't confirmed this will work end to end myself. |
Thanks for your info! |
Going to close this, as we don't currently plan to open up for alternative protocols. With a working example (a fork?) to review we could consider reopening. But not guaranteed either. |
It looks only SSL/TLS protocols are supported by OkHttpClient.
Could OkHttp allow other protocols?
Say, an alternative SSLContext implementation supports a non-TLS protocol and cipher suites.
This SSLContext implementation provides its own SSLSocketFactory.
Generally, that would be ready for working.
However, it looks OkHttpClient/ConnectionSpec requires the protocols must be in TlsVersion.
Could this restriction be removed?
For example, OkHttpClient just need to receive strings as protocols, but not need to convert them to TlsVersion instances.
The text was updated successfully, but these errors were encountered: