Skip to content
Permalink
Browse files

Workaround: Prevent OkHttpClient from opening an HTTP/2 connection

OkHttp does not play nicely with nginx over HTTP/2 and this is causing
our connection to fail when trying to log in or make an edit.

This workaround will fix our issue while Square works on resolving
square/okhttp#2543 .

Bug: T134758
Bug: T134759
Change-Id: Ifc2ec3eb75e2e54b4789914f43ff9104f1ca11f9
  • Loading branch information
mdholloway committed May 9, 2016
1 parent 87b690a commit 058ed9cb5f4b77411f113cb31820e4a8687ee11a
Showing with 12 additions and 0 deletions.
  1. +12 −0 app/src/main/java/org/wikipedia/OkHttpConnectionFactory.java
@@ -5,11 +5,14 @@
import com.squareup.okhttp.Cache;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.OkUrlFactory;
import com.squareup.okhttp.Protocol;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.Proxy;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

public class OkHttpConnectionFactory implements HttpRequest.ConnectionFactory {
private static final long HTTP_CACHE_SIZE = 16 * 1024 * 1024;
@@ -35,6 +38,15 @@ public static OkHttpClient createClient(Context context) {
OkHttpClient client = new OkHttpClient();
client.setCookieHandler(((WikipediaApp)context.getApplicationContext()).getCookieManager());
client.setCache(new Cache(context.getCacheDir(), HTTP_CACHE_SIZE));

// Create a custom set of protocols that excludes HTTP/2, since OkHttp doesn't play
// nicely with nginx over HTTP/2.
// TODO: Remove when https://github.com/square/okhttp/issues/2543 is fixed.
List<Protocol> protocolList = new ArrayList<>();
protocolList.add(Protocol.SPDY_3);
protocolList.add(Protocol.HTTP_1_1);
client.setProtocols(protocolList);

return client;
}
}

0 comments on commit 058ed9c

Please sign in to comment.
You can’t perform that action at this time.