KeyBaseLib response Client

This commit is contained in:
Michal Kepkowski
2016-04-08 19:10:59 +02:00
parent 26bfe06d80
commit 7b97c2bbed
2 changed files with 10 additions and 10 deletions

View File

@@ -119,7 +119,7 @@ public class LinkedIdCreateTwitterStep1Fragment extends Fragment {
private static Boolean checkHandle(String handle) { private static Boolean checkHandle(String handle) {
try { try {
HttpURLConnection nection = HttpURLConnection nection =
(HttpURLConnection) new URL("https://twitter.com/" + handle).openConnection(); (HttpURLConnection) new URL("https://twitter.com/" + handle).getUrlResponse();
nection.setRequestMethod("HEAD"); nection.setRequestMethod("HEAD");
nection.setRequestProperty("User-Agent", "OpenKeychain"); nection.setRequestProperty("User-Agent", "OpenKeychain");
return nection.getResponseCode() == 200; return nection.getResponseCode() == 200;

View File

@@ -22,6 +22,8 @@ import com.textuality.keybase.lib.KeybaseUrlConnectionClient;
import okhttp3.OkHttpClient; import okhttp3.OkHttpClient;
import okhttp3.OkUrlFactory; import okhttp3.OkUrlFactory;
import okhttp3.Request;
import okhttp3.Response;
import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.Constants;
import java.io.IOException; import java.io.IOException;
@@ -34,16 +36,12 @@ import java.net.URLConnection;
*/ */
public class OkHttpKeybaseClient implements KeybaseUrlConnectionClient { public class OkHttpKeybaseClient implements KeybaseUrlConnectionClient {
private OkUrlFactory generateUrlFactory() {
OkHttpClient client = new OkHttpClient();
return new OkUrlFactory(client);
}
@Override @Override
public URLConnection openConnection(URL url, Proxy proxy, boolean isKeybase) throws IOException { public Response getUrlResponse(URL url, Proxy proxy, boolean isKeybase) throws IOException {
OkHttpClient client = OkHttpClientFactory.getSimpleClient(); OkHttpClient client = null;
OkUrlFactory factory = generateUrlFactory();
try { try {
if (isKeybase && proxy != null) { if (isKeybase && proxy != null) {
client = OkHttpClientFactory.getPinnedClient(url, proxy); client = OkHttpClientFactory.getPinnedClient(url, proxy);
@@ -56,9 +54,11 @@ public class OkHttpKeybaseClient implements KeybaseUrlConnectionClient {
Log.e(Constants.TAG, "TlsHelper failed", e); Log.e(Constants.TAG, "TlsHelper failed", e);
throw new IOException("TlsHelper failed"); throw new IOException("TlsHelper failed");
} }
factory.setClient(client);
return factory.open(url); Request request = new Request.Builder()
.url(url).build();
okhttp3.Response okResponse = client.newCall(request).execute();
return new Response(okResponse.body().byteStream(),okResponse.code(),okResponse.message(), okResponse.headers().toMultimap());
} }
@Override @Override