I am using Retrofit 1.9 with okhttp 2.4.0. So far we have SPDY protocol disabled on server side (I checked it by this ). And enabled protocol on server side is HTTP/2 (I checked it by this).
So I was thinking that okhttp will try to make an api call using HTTP/2 (latest one protocol) but it's using HTTP/1.1 on android device 4.2.2 samsung S4 -
D/Retrofit : OkHttp-Selected-Protocol: http/1.1
Someone told me that android device doesn't support SPDY until 5.0 (I don't have any proof), so that device never attempted to use a SPDY connection. But I am sure that our server not using SPDY at all I checked it by myself using above link.
And okhttp start supporting HTTP/2 since it's 2.3.0 version see here.
And if I use same thing in android 5.0 above I got an exception with same configuration (okhttp 2.4.0 and Retrofit 1.9) on a production app -
java.net.ProtocolException: Expected ':status' header not present at
com.squareup.okhttp.internal.http.SpdyTransport.readNameValueBlock(SpdyTransport.java:197)at com.squareup.okhttp.internal.http.SpdyTransport.readResponseHeaders(SpdyTransport.java:104)
at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(HttpEngine.java:917)
at com.squareup.okhttp.internal.http.HttpEngine.access$300(HttpEngine.java:95)
at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:902)
at com.squareup.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:760)
at com.squareup.okhttp.Call.getResponse(Call.java:274)
at com.squareup.okhttp.Call$ApplicationInterceptorChain.proceed(Call.java:230)
at com.squareup.okhttp.Call.getResponseWithInterceptorChain(Call.java:201)
at com.squareup.okhttp.Call.execute(Call.java:81)
at retrofit.client.OkClient.execute(OkClient.java:53)
at retrofit.RestAdapter$RestHandler.invokeRequest(RestAdapter.java:326)
at retrofit.RestAdapter$RestHandler.access$100(RestAdapter.java:220)
at retrofit.RestAdapter$RestHandler$2.obtainResponse(RestAdapter.java:278)
at retrofit.CallbackRunnable.run(CallbackRunnable.java:42)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
at retrofit.Platform$Android$2$1.run(Platform.java:142)
at java.lang.Thread.run(Thread.java:818)
And there was two fix -
Force the okhttp to use only http/1.1 -
OkHttpClient client = new OkHttpClient(); client.setProtocols(Arrays.asList(Protocol.HTTP_1_1));
Note - We can't use Protocol.HTTP_2 OR Protocol.SPDY_3 because OkHttp will automatically use HTTP/2 if it’s available, but you can’t disable HTTP/1.1.
- And upgrading the okhttp2.4.0 to okhttp 3.
But app is already in production so I can't make these two changes on app and client asks me for the explanation for this - "Why app suddenly went down? Yesterday it was working but what happen now?"
Note - App is working fine on all the server endpoints that does not support HTTP/2. And I am using Sucuri that already supporting HTTP/2.
Truly I don't have any explanation on this -
- Is really android doesn't support http/2 protocol on less than 5.0 android device (because app is working fine with okhttp 2.4.0)?
- Is Okhttp 2.4.0 doesn't support HTTP/2 well and if it is support then why its choosing http/1.1 protocol on 4.4.2 device?
- Is android device always try to use HTTP/2 protocol if it is supported at server side? (Might be in my case it's trying to use HTTP/2 protocol and Okhttp 2.4.0 don't have the proper handing of it, that's why it's failing in 5.0 above devices).
- What can be real cause for app stopped working suddenly? (I was thinking that there might be some upgradation or drops that okhttp 2.4 doesn't handling well that cause app stopped working).
- Sucuri is already supporting HTTP/2 since 2015 then what config changes my app stop working? (Yesterday my app was working on all the devices with okhttp2.4.0 and with retrofit 1.9 on same endpoints.)
So I want a better explanation or proof so that I can explain to my client.
Here are some links I followed - this and okhttp change logs and this discussion, reply from okhttp team.
Thanks. Happy coding :)