/* GENERATED SOURCE. DO NOT MODIFY. */ /* * Copyright (C) 2012 Square, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.android.okhttp; import com.android.okhttp.internal.Internal; import com.android.okhttp.internal.InternalCache; import com.android.okhttp.internal.RouteDatabase; import com.android.okhttp.internal.Util; import com.android.okhttp.internal.http.AuthenticatorAdapter; import com.android.okhttp.internal.http.StreamAllocation; import com.android.okhttp.internal.io.RealConnection; import com.android.okhttp.internal.tls.OkHostnameVerifier; import java.net.CookieHandler; import java.net.MalformedURLException; import java.net.Proxy; import java.net.ProxySelector; import java.net.URLConnection; import java.net.UnknownHostException; import java.security.GeneralSecurityException; import java.util.ArrayList; import java.util.List; import java.util.concurrent.TimeUnit; import javax.net.SocketFactory; import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocket; import javax.net.ssl.SSLSocketFactory; /** * Configures and creates HTTP connections. Most applications can use a single * OkHttpClient for all of their HTTP requests - benefiting from a shared * response cache, thread pool, connection re-use, etc. * *
Instances of OkHttpClient are intended to be fully configured before they're
* shared - once shared they should be treated as immutable and can safely be used
* to concurrently open new connections. If required, threads can call
* {@link #clone()} to make a shallow copy of the OkHttpClient that can be
* safely modified with further configuration changes.
* @hide This class is not part of the Android public SDK API
*/
public class OkHttpClient implements Cloneable {
@android.compat.annotation.UnsupportedAppUsage
private static final List If unset, the {@link ProxySelector#getDefault() system-wide default}
* proxy selector will be used.
*/
public OkHttpClient setProxySelector(ProxySelector proxySelector) {
this.proxySelector = proxySelector;
return this;
}
@android.compat.annotation.UnsupportedAppUsage
public ProxySelector getProxySelector() {
return proxySelector;
}
/**
* Sets the cookie handler to be used to read outgoing cookies and write
* incoming cookies.
*
* If unset, the {@link CookieHandler#getDefault() system-wide default}
* cookie handler will be used.
*/
public OkHttpClient setCookieHandler(CookieHandler cookieHandler) {
this.cookieHandler = cookieHandler;
return this;
}
@android.compat.annotation.UnsupportedAppUsage
public CookieHandler getCookieHandler() {
return cookieHandler;
}
/** Sets the response cache to be used to read and write cached responses. */
void setInternalCache(InternalCache internalCache) {
this.internalCache = internalCache;
this.cache = null;
}
InternalCache internalCache() {
return internalCache;
}
public OkHttpClient setCache(Cache cache) {
this.cache = cache;
this.internalCache = null;
return this;
}
public Cache getCache() {
return cache;
}
/**
* Sets the DNS service used to lookup IP addresses for hostnames.
*
* If unset, the {@link Dns#SYSTEM system-wide default} DNS will be used.
*/
public OkHttpClient setDns(Dns dns) {
this.dns = dns;
return this;
}
public Dns getDns() {
return dns;
}
/**
* Sets the socket factory used to create connections. OkHttp only uses
* the parameterless {@link SocketFactory#createSocket() createSocket()}
* method to create unconnected sockets. Overriding this method,
* e. g., allows the socket to be bound to a specific local address.
*
* If unset, the {@link SocketFactory#getDefault() system-wide default}
* socket factory will be used.
*/
public OkHttpClient setSocketFactory(SocketFactory socketFactory) {
this.socketFactory = socketFactory;
return this;
}
public SocketFactory getSocketFactory() {
return socketFactory;
}
/**
* Sets the socket factory used to secure HTTPS connections.
*
* If unset, a lazily created SSL socket factory will be used.
*/
public OkHttpClient setSslSocketFactory(SSLSocketFactory sslSocketFactory) {
this.sslSocketFactory = sslSocketFactory;
return this;
}
@android.compat.annotation.UnsupportedAppUsage
public SSLSocketFactory getSslSocketFactory() {
return sslSocketFactory;
}
/**
* Sets the verifier used to confirm that response certificates apply to
* requested hostnames for HTTPS connections.
*
* If unset, a default hostname verifier will be used.
*/
public OkHttpClient setHostnameVerifier(HostnameVerifier hostnameVerifier) {
this.hostnameVerifier = hostnameVerifier;
return this;
}
@android.compat.annotation.UnsupportedAppUsage
public HostnameVerifier getHostnameVerifier() {
return hostnameVerifier;
}
/**
* Sets the certificate pinner that constrains which certificates are trusted.
* By default HTTPS connections rely on only the {@link #setSslSocketFactory
* SSL socket factory} to establish trust. Pinning certificates avoids the
* need to trust certificate authorities.
*/
public OkHttpClient setCertificatePinner(CertificatePinner certificatePinner) {
this.certificatePinner = certificatePinner;
return this;
}
public CertificatePinner getCertificatePinner() {
return certificatePinner;
}
/**
* Sets the authenticator used to respond to challenges from the remote web
* server or proxy server.
*
* If unset, the {@link java.net.Authenticator#setDefault system-wide default}
* authenticator will be used.
*/
public OkHttpClient setAuthenticator(Authenticator authenticator) {
this.authenticator = authenticator;
return this;
}
public Authenticator getAuthenticator() {
return authenticator;
}
/**
* Sets the connection pool used to recycle HTTP and HTTPS connections.
*
* If unset, the {@link ConnectionPool#getDefault() system-wide
* default} connection pool will be used.
*/
public OkHttpClient setConnectionPool(ConnectionPool connectionPool) {
this.connectionPool = connectionPool;
return this;
}
@android.compat.annotation.UnsupportedAppUsage
public ConnectionPool getConnectionPool() {
return connectionPool;
}
/**
* Configure this client to follow redirects from HTTPS to HTTP and from HTTP
* to HTTPS.
*
* If unset, protocol redirects will be followed. This is different than
* the built-in {@code HttpURLConnection}'s default.
*/
public OkHttpClient setFollowSslRedirects(boolean followProtocolRedirects) {
this.followSslRedirects = followProtocolRedirects;
return this;
}
public boolean getFollowSslRedirects() {
return followSslRedirects;
}
/** Configure this client to follow redirects. If unset, redirects be followed. */
public void setFollowRedirects(boolean followRedirects) {
this.followRedirects = followRedirects;
}
public boolean getFollowRedirects() {
return followRedirects;
}
/**
* Configure this client to retry or not when a connectivity problem is encountered. By default,
* this client silently recovers from the following problems:
*
* The following protocols are currently supported:
* This is an evolving set. Future releases include
* support for transitional protocols. The http/1.1 transport will never be
* dropped.
*
* If multiple protocols are specified, ALPN
* will be used to negotiate a transport.
*
* {@link Protocol#HTTP_1_0} is not supported in this set. Requests are
* initiated with {@code HTTP/1.1} only. If the server responds with {@code
* HTTP/1.0}, that will be exposed by {@link Response#protocol()}.
*
* @param protocols the protocols to use, in order of preference. The list
* must contain {@link Protocol#HTTP_1_1}. It must not contain null or
* {@link Protocol#HTTP_1_0}.
*/
@android.compat.annotation.UnsupportedAppUsage
public OkHttpClient setProtocols(List This code avoids that by defaulting to an OkHttp-created SSL context.
* The drawback of this approach is that apps that customize the global SSL
* context will lose these customizations.
*/
private synchronized SSLSocketFactory getDefaultSSLSocketFactory() {
if (defaultSslSocketFactory == null) {
try {
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, null, null);
defaultSslSocketFactory = sslContext.getSocketFactory();
} catch (GeneralSecurityException e) {
throw new AssertionError(); // The system has no TLS. Just give up.
}
}
return defaultSslSocketFactory;
}
/** Returns a shallow copy of this OkHttpClient. */
@Override public OkHttpClient clone() {
return new OkHttpClient(this);
}
}
*
*
* Set this to false to avoid retrying requests when doing so is destructive. In this case the
* calling application should do its own recovery of connectivity failures.
*/
@android.compat.annotation.UnsupportedAppUsage
public void setRetryOnConnectionFailure(boolean retryOnConnectionFailure) {
this.retryOnConnectionFailure = retryOnConnectionFailure;
}
public boolean getRetryOnConnectionFailure() {
return retryOnConnectionFailure;
}
RouteDatabase routeDatabase() {
return routeDatabase;
}
/**
* Sets the dispatcher used to set policy and execute asynchronous requests.
* Must not be null.
*/
public OkHttpClient setDispatcher(Dispatcher dispatcher) {
if (dispatcher == null) throw new IllegalArgumentException("dispatcher == null");
this.dispatcher = dispatcher;
return this;
}
public Dispatcher getDispatcher() {
return dispatcher;
}
/**
* Configure the protocols used by this client to communicate with remote
* servers. By default this client will prefer the most efficient transport
* available, falling back to more ubiquitous protocols. Applications should
* only call this method to avoid specific compatibility problems, such as web
* servers that behave incorrectly when SPDY is enabled.
*
*