OkHttp, HTTP/2 & NGINX 1.9.5

OkHttp’s HTTP/2 doesn’t interop with NGINX 1.9.5. HTTP requests made from OkHttp to impacted NGINX servers will fail like this: stream was reset: PROTOCOL_ERROR  
    at com.squareup.okhttp.internal.spdy.SpdyStream.getResponseHeaders(
    at com.squareup.okhttp.internal.http.SpdyTransport.readResponseHeaders(
    at com.squareup.okhttp.internal.http.HttpEngine.readNetworkResponse(
    at com.squareup.okhttp.internal.http.HttpEngine.access$200(
    at com.squareup.okhttp.internal.http.HttpEngine$NetworkInterceptorChain.proceed(
    at com.squareup.okhttp.internal.http.HttpEngine.readResponse(
    at com.squareup.okhttp.Call.getResponse(

They’ve merged a fix. In the interim, you can either downgrade your NGINX or disable HTTP/2 in OkHttp:

OkHttpClient client = new OkHttpClient();

// Disable HTTP/2 for interop with NGINX 1.9.5.
// TODO: remove this hack after 2015-12-31.

HPACK is what HTTP/2 uses to compress headers. It’s a bit tricky to get right, partially because there are multiple ways to encode headers. In this case OkHttp’s compression strategy triggered a different code path than the major browsers.