List of usage examples for com.squareup.okhttp OkHttpClient setFollowRedirects
public void setFollowRedirects(boolean followRedirects)
From source file:org.sufficientlysecure.keychain.keyimport.HkpKeyserver.java
License:Apache License
/** * returns a client with pinned certificate if necessary * * @param url url to be queried by client * @param proxy proxy to be used by client * @return client with a pinned certificate if necessary *//* ww w . j a v a 2s . co m*/ public static OkHttpClient getClient(URL url, Proxy proxy) throws IOException { OkHttpClient client = new OkHttpClient(); try { TlsHelper.usePinnedCertificateIfAvailable(client, url); } catch (TlsHelper.TlsHelperException e) { Log.w(Constants.TAG, e); } // don't follow any redirects client.setFollowRedirects(false); client.setFollowSslRedirects(false); if (proxy != null) { client.setProxy(proxy); client.setConnectTimeout(30000, TimeUnit.MILLISECONDS); } else { client.setProxy(Proxy.NO_PROXY); client.setConnectTimeout(5000, TimeUnit.MILLISECONDS); } client.setReadTimeout(45000, TimeUnit.MILLISECONDS); return client; }
From source file:org.sufficientlysecure.keychain.ui.dialog.AddEditKeyserverDialogFragment.java
License:Open Source License
public void verifyConnection(String keyserver, final Proxy proxy, final boolean onlyTrustedKeyserver) { new AsyncTask<String, Void, FailureReason>() { ProgressDialog mProgressDialog;//from w w w. j a v a2 s. c o m String mKeyserver; @Override protected void onPreExecute() { mProgressDialog = new ProgressDialog(getActivity()); mProgressDialog.setMessage(getString(R.string.progress_verifying_keyserver_connection)); mProgressDialog.setCancelable(false); mProgressDialog.show(); } @Override protected FailureReason doInBackground(String... keyservers) { mKeyserver = keyservers[0]; FailureReason reason = null; try { // replace hkps/hkp scheme and reconstruct Uri Uri keyserverUri = Uri.parse(mKeyserver); String scheme = keyserverUri.getScheme(); String schemeSpecificPart = keyserverUri.getSchemeSpecificPart(); String fragment = keyserverUri.getFragment(); if (scheme == null) { throw new MalformedURLException(); } if ("hkps".equalsIgnoreCase(scheme)) { scheme = "https"; } else if ("hkp".equalsIgnoreCase(scheme)) { scheme = "http"; } URI newKeyserver = new URI(scheme, schemeSpecificPart, fragment); Log.d("Converted URL", newKeyserver.toString()); OkHttpClient client = HkpKeyserver.getClient(newKeyserver.toURL(), proxy); // don't follow any redirects client.setFollowRedirects(false); client.setFollowSslRedirects(false); if (onlyTrustedKeyserver && !TlsHelper.usePinnedCertificateIfAvailable(client, newKeyserver.toURL())) { Log.w(Constants.TAG, "No pinned certificate for this host in OpenKeychain's assets."); reason = FailureReason.NO_PINNED_CERTIFICATE; return reason; } client.newCall(new Request.Builder().url(newKeyserver.toURL()).build()).execute(); } catch (TlsHelper.TlsHelperException e) { reason = FailureReason.CONNECTION_FAILED; } catch (MalformedURLException | URISyntaxException e) { Log.w(Constants.TAG, "Invalid keyserver URL entered by user."); reason = FailureReason.INVALID_URL; } catch (IOException e) { Log.w(Constants.TAG, "Could not connect to entered keyserver url"); reason = FailureReason.CONNECTION_FAILED; } return reason; } @Override protected void onPostExecute(FailureReason failureReason) { mProgressDialog.dismiss(); if (failureReason == null) { keyserverEdited(mKeyserver, true); } else { verificationFailed(failureReason); } } }.execute(keyserver); }
From source file:ti.okhttp.TiOkhttpclient.java
License:Open Source License
protected void setUpClient(OkHttpClient client) { client.setFollowRedirects(autoRedirect); client.setFollowSslRedirects(autoRedirect); }