简体   繁体   中英

Okhttp3 with consrypt for http2 support in jdk8

I've been testing around okhttp3 for making http2 requests, my criteria is to achieve http2 connection using jdk8 itself. I knew this can be easily achieved by upgrading to jdk 9 or using conscrypt as default provider like,

Security.insertProviderAt(Conscrypt.newProvider(), 1);

But inserting the provider like this will affect at the application level, I just want to restrict this only to the sslSocket which uses http2 connection, all the other sockets should use default provider, I knew apache-httpclient-5 beta provide such option called custom TLSstrategy which helps to assign conscrypt as default provider only for the specific SSLSocketFactory

Kindly help

TIA

It isn't really designed for that case, rather the assumption is that if you have Conscrypt available and registered then you are happy and willing to use it.

The OkHttp Platform is auto selected and a JVM singleton, so you can't override per client, or per connection.

You can possibly override the SSLSocketFactory for a client. However, OkHttp also requires the HTTP/1.1 is one of the acceptable protocols, and the TLS Provider will be selected before the client and server negotiate HTTP/1.1 or H2. So this may or may not work for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM