what-the-bank/sources/okhttp3/repackaged/OkHttpClient.java

592 lines
21 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package okhttp3.repackaged;
import com.huawei.hms.android.HwBuildEx;
import java.net.MalformedURLException;
import java.net.Proxy;
import java.net.ProxySelector;
import java.net.UnknownHostException;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
import java.util.Iterator;
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;
import javax.net.ssl.X509TrustManager;
import okhttp3.repackaged.Call;
import okhttp3.repackaged.Headers;
import okhttp3.repackaged.internal.Internal;
import okhttp3.repackaged.internal.InternalCache;
import okhttp3.repackaged.internal.Platform;
import okhttp3.repackaged.internal.RouteDatabase;
import okhttp3.repackaged.internal.Util;
import okhttp3.repackaged.internal.http.StreamAllocation;
import okhttp3.repackaged.internal.io.RealConnection;
import okhttp3.repackaged.internal.tls.OkHostnameVerifier;
import okhttp3.repackaged.internal.tls.TrustRootIndex;
/* loaded from: classes6.dex */
public class OkHttpClient implements Cloneable, Call.Factory {
final InternalCache agE;
final Dns agx;
final Authenticator agy;
final CertificatePinner agz;
final TrustRootIndex ahf;
final Dispatcher aik;
final CookieJar ail;
final Cache aim;
final Authenticator ain;
final ConnectionPool aio;
final int connectTimeout;
final List<ConnectionSpec> connectionSpecs;
final boolean followRedirects;
final boolean followSslRedirects;
final HostnameVerifier hostnameVerifier;
final List<Interceptor> interceptors;
final List<Interceptor> networkInterceptors;
final List<Protocol> protocols;
final Proxy proxy;
final ProxySelector proxySelector;
final int readTimeout;
final boolean retryOnConnectionFailure;
final SocketFactory socketFactory;
final SSLSocketFactory sslSocketFactory;
final int writeTimeout;
private static final List<Protocol> DEFAULT_PROTOCOLS = Util.immutableList(Protocol.HTTP_2, Protocol.SPDY_3, Protocol.HTTP_1_1);
private static final List<ConnectionSpec> DEFAULT_CONNECTION_SPECS = Util.immutableList(ConnectionSpec.MODERN_TLS, ConnectionSpec.COMPATIBLE_TLS, ConnectionSpec.CLEARTEXT);
static {
Internal.instance = new Internal() { // from class: okhttp3.repackaged.OkHttpClient.1
@Override // okhttp3.repackaged.internal.Internal
public final void addLenient(Headers.Builder builder, String str) {
builder.aT(str);
}
@Override // okhttp3.repackaged.internal.Internal
public final void addLenient(Headers.Builder builder, String str, String str2) {
builder.U(str, str2);
}
@Override // okhttp3.repackaged.internal.Internal
public final void setCache(Builder builder, InternalCache internalCache) {
builder.a(internalCache);
}
@Override // okhttp3.repackaged.internal.Internal
public final InternalCache internalCache(OkHttpClient okHttpClient) {
return okHttpClient.uq();
}
@Override // okhttp3.repackaged.internal.Internal
public final boolean connectionBecameIdle(ConnectionPool connectionPool, RealConnection realConnection) {
return connectionPool.b(realConnection);
}
@Override // okhttp3.repackaged.internal.Internal
public final RealConnection get(ConnectionPool connectionPool, Address address, StreamAllocation streamAllocation) {
return connectionPool.a(address, streamAllocation);
}
@Override // okhttp3.repackaged.internal.Internal
public final void put(ConnectionPool connectionPool, RealConnection realConnection) {
connectionPool.a(realConnection);
}
@Override // okhttp3.repackaged.internal.Internal
public final RouteDatabase routeDatabase(ConnectionPool connectionPool) {
return connectionPool.aho;
}
@Override // okhttp3.repackaged.internal.Internal
public final void callEnqueue(Call call, Callback callback, boolean z) {
((a) call).a(callback, z);
}
@Override // okhttp3.repackaged.internal.Internal
public final StreamAllocation callEngineGetStreamAllocation(Call call) {
return ((a) call).aiw.streamAllocation;
}
@Override // okhttp3.repackaged.internal.Internal
public final void apply(ConnectionSpec connectionSpec, SSLSocket sSLSocket, boolean z) {
connectionSpec.apply(sSLSocket, z);
}
@Override // okhttp3.repackaged.internal.Internal
public final HttpUrl getHttpUrlChecked(String str) throws MalformedURLException, UnknownHostException {
return HttpUrl.aU(str);
}
};
}
public OkHttpClient() {
this(new Builder());
}
private OkHttpClient(Builder builder) {
boolean z;
this.aik = builder.aik;
this.proxy = builder.proxy;
this.protocols = builder.protocols;
List<ConnectionSpec> list = builder.connectionSpecs;
this.connectionSpecs = list;
this.interceptors = Util.immutableList(builder.interceptors);
this.networkInterceptors = Util.immutableList(builder.networkInterceptors);
this.proxySelector = builder.proxySelector;
this.ail = builder.ail;
this.aim = builder.aim;
this.agE = builder.agE;
this.socketFactory = builder.socketFactory;
Iterator<ConnectionSpec> it = list.iterator();
loop0: while (true) {
while (it.hasNext()) {
z = z || it.next().isTls();
}
}
if (builder.sslSocketFactory != null || !z) {
this.sslSocketFactory = builder.sslSocketFactory;
} else {
try {
SSLContext sSLContext = SSLContext.getInstance(org.apache.http.conn.ssl.SSLSocketFactory.TLS);
sSLContext.init(null, null, null);
this.sslSocketFactory = sSLContext.getSocketFactory();
} catch (GeneralSecurityException unused) {
throw new AssertionError();
}
}
if (this.sslSocketFactory != null && builder.ahf == null) {
X509TrustManager trustManager = Platform.get().trustManager(this.sslSocketFactory);
if (trustManager == null) {
StringBuilder sb = new StringBuilder("Unable to extract the trust manager on ");
sb.append(Platform.get());
sb.append(", sslSocketFactory is ");
sb.append(this.sslSocketFactory.getClass());
throw new IllegalStateException(sb.toString());
}
TrustRootIndex trustRootIndex = Platform.get().trustRootIndex(trustManager);
this.ahf = trustRootIndex;
this.agz = builder.agz.um().trustRootIndex(trustRootIndex).build();
} else {
this.ahf = builder.ahf;
this.agz = builder.agz;
}
this.hostnameVerifier = builder.hostnameVerifier;
this.agy = builder.agy;
this.ain = builder.ain;
this.aio = builder.aio;
this.agx = builder.agx;
this.followSslRedirects = builder.followSslRedirects;
this.followRedirects = builder.followRedirects;
this.retryOnConnectionFailure = builder.retryOnConnectionFailure;
this.connectTimeout = builder.connectTimeout;
this.readTimeout = builder.readTimeout;
this.writeTimeout = builder.writeTimeout;
}
InternalCache uq() {
Cache cache = this.aim;
return cache != null ? cache.agE : this.agE;
}
@Override // okhttp3.repackaged.Call.Factory
public Call newCall(Request request) {
return new a(this, request);
}
public Builder newBuilder() {
return new Builder(this);
}
/* loaded from: classes6.dex */
public static final class Builder {
InternalCache agE;
Dns agx;
Authenticator agy;
CertificatePinner agz;
TrustRootIndex ahf;
Dispatcher aik;
CookieJar ail;
Cache aim;
Authenticator ain;
ConnectionPool aio;
int connectTimeout;
List<ConnectionSpec> connectionSpecs;
boolean followRedirects;
boolean followSslRedirects;
HostnameVerifier hostnameVerifier;
final List<Interceptor> interceptors;
final List<Interceptor> networkInterceptors;
List<Protocol> protocols;
Proxy proxy;
ProxySelector proxySelector;
int readTimeout;
boolean retryOnConnectionFailure;
SocketFactory socketFactory;
SSLSocketFactory sslSocketFactory;
int writeTimeout;
public Builder() {
this.interceptors = new ArrayList();
this.networkInterceptors = new ArrayList();
this.aik = new Dispatcher();
this.protocols = OkHttpClient.DEFAULT_PROTOCOLS;
this.connectionSpecs = OkHttpClient.DEFAULT_CONNECTION_SPECS;
this.proxySelector = ProxySelector.getDefault();
this.ail = CookieJar.NO_COOKIES;
this.socketFactory = SocketFactory.getDefault();
this.hostnameVerifier = OkHostnameVerifier.INSTANCE;
this.agz = CertificatePinner.DEFAULT;
this.agy = Authenticator.NONE;
this.ain = Authenticator.NONE;
this.aio = new ConnectionPool();
this.agx = Dns.SYSTEM;
this.followSslRedirects = true;
this.followRedirects = true;
this.retryOnConnectionFailure = true;
this.connectTimeout = HwBuildEx.VersionCodes.CUR_DEVELOPMENT;
this.readTimeout = HwBuildEx.VersionCodes.CUR_DEVELOPMENT;
this.writeTimeout = HwBuildEx.VersionCodes.CUR_DEVELOPMENT;
}
Builder(OkHttpClient okHttpClient) {
ArrayList arrayList = new ArrayList();
this.interceptors = arrayList;
ArrayList arrayList2 = new ArrayList();
this.networkInterceptors = arrayList2;
this.aik = okHttpClient.aik;
this.proxy = okHttpClient.proxy;
this.protocols = okHttpClient.protocols;
this.connectionSpecs = okHttpClient.connectionSpecs;
arrayList.addAll(okHttpClient.interceptors);
arrayList2.addAll(okHttpClient.networkInterceptors);
this.proxySelector = okHttpClient.proxySelector;
this.ail = okHttpClient.ail;
this.agE = okHttpClient.agE;
this.aim = okHttpClient.aim;
this.socketFactory = okHttpClient.socketFactory;
this.sslSocketFactory = okHttpClient.sslSocketFactory;
this.ahf = okHttpClient.ahf;
this.hostnameVerifier = okHttpClient.hostnameVerifier;
this.agz = okHttpClient.agz;
this.agy = okHttpClient.agy;
this.ain = okHttpClient.ain;
this.aio = okHttpClient.aio;
this.agx = okHttpClient.agx;
this.followSslRedirects = okHttpClient.followSslRedirects;
this.followRedirects = okHttpClient.followRedirects;
this.retryOnConnectionFailure = okHttpClient.retryOnConnectionFailure;
this.connectTimeout = okHttpClient.connectTimeout;
this.readTimeout = okHttpClient.readTimeout;
this.writeTimeout = okHttpClient.writeTimeout;
}
public final Builder connectTimeout(long j, TimeUnit timeUnit) {
if (j < 0) {
throw new IllegalArgumentException("timeout < 0");
}
if (timeUnit == null) {
throw new IllegalArgumentException("unit == null");
}
long millis = timeUnit.toMillis(j);
if (millis > 2147483647L) {
throw new IllegalArgumentException("Timeout too large.");
}
if (millis == 0 && j > 0) {
throw new IllegalArgumentException("Timeout too small.");
}
this.connectTimeout = (int) millis;
return this;
}
public final Builder readTimeout(long j, TimeUnit timeUnit) {
if (j < 0) {
throw new IllegalArgumentException("timeout < 0");
}
if (timeUnit == null) {
throw new IllegalArgumentException("unit == null");
}
long millis = timeUnit.toMillis(j);
if (millis > 2147483647L) {
throw new IllegalArgumentException("Timeout too large.");
}
if (millis == 0 && j > 0) {
throw new IllegalArgumentException("Timeout too small.");
}
this.readTimeout = (int) millis;
return this;
}
public final Builder writeTimeout(long j, TimeUnit timeUnit) {
if (j < 0) {
throw new IllegalArgumentException("timeout < 0");
}
if (timeUnit == null) {
throw new IllegalArgumentException("unit == null");
}
long millis = timeUnit.toMillis(j);
if (millis > 2147483647L) {
throw new IllegalArgumentException("Timeout too large.");
}
if (millis == 0 && j > 0) {
throw new IllegalArgumentException("Timeout too small.");
}
this.writeTimeout = (int) millis;
return this;
}
public final Builder cookieJar(CookieJar cookieJar) {
if (cookieJar == null) {
throw new NullPointerException("cookieJar == null");
}
this.ail = cookieJar;
return this;
}
public final Builder dns(Dns dns) {
if (dns == null) {
throw new NullPointerException("dns == null");
}
this.agx = dns;
return this;
}
public final Builder socketFactory(SocketFactory socketFactory) {
if (socketFactory == null) {
throw new NullPointerException("socketFactory == null");
}
this.socketFactory = socketFactory;
return this;
}
public final Builder sslSocketFactory(SSLSocketFactory sSLSocketFactory) {
if (sSLSocketFactory == null) {
throw new NullPointerException("sslSocketFactory == null");
}
this.sslSocketFactory = sSLSocketFactory;
this.ahf = null;
return this;
}
public final Builder hostnameVerifier(HostnameVerifier hostnameVerifier) {
if (hostnameVerifier == null) {
throw new NullPointerException("hostnameVerifier == null");
}
this.hostnameVerifier = hostnameVerifier;
return this;
}
public final Builder certificatePinner(CertificatePinner certificatePinner) {
if (certificatePinner == null) {
throw new NullPointerException("certificatePinner == null");
}
this.agz = certificatePinner;
return this;
}
public final Builder authenticator(Authenticator authenticator) {
if (authenticator == null) {
throw new NullPointerException("authenticator == null");
}
this.ain = authenticator;
return this;
}
public final Builder proxyAuthenticator(Authenticator authenticator) {
if (authenticator == null) {
throw new NullPointerException("proxyAuthenticator == null");
}
this.agy = authenticator;
return this;
}
public final Builder connectionPool(ConnectionPool connectionPool) {
if (connectionPool == null) {
throw new NullPointerException("connectionPool == null");
}
this.aio = connectionPool;
return this;
}
public final Builder dispatcher(Dispatcher dispatcher) {
if (dispatcher == null) {
throw new IllegalArgumentException("dispatcher == null");
}
this.aik = dispatcher;
return this;
}
public final Builder protocols(List<Protocol> list) {
List immutableList = Util.immutableList(list);
if (!immutableList.contains(Protocol.HTTP_1_1)) {
throw new IllegalArgumentException("protocols doesn't contain http/1.1: ".concat(String.valueOf(immutableList)));
}
if (immutableList.contains(Protocol.HTTP_1_0)) {
throw new IllegalArgumentException("protocols must not contain http/1.0: ".concat(String.valueOf(immutableList)));
}
if (immutableList.contains(null)) {
throw new IllegalArgumentException("protocols must not contain null");
}
this.protocols = Util.immutableList(immutableList);
return this;
}
public final Builder connectionSpecs(List<ConnectionSpec> list) {
this.connectionSpecs = Util.immutableList(list);
return this;
}
public final Builder addInterceptor(Interceptor interceptor) {
this.interceptors.add(interceptor);
return this;
}
public final Builder addNetworkInterceptor(Interceptor interceptor) {
this.networkInterceptors.add(interceptor);
return this;
}
public final OkHttpClient build() {
return new OkHttpClient(this);
}
public final Builder retryOnConnectionFailure(boolean z) {
this.retryOnConnectionFailure = z;
return this;
}
public final Builder proxySelector(ProxySelector proxySelector) {
this.proxySelector = proxySelector;
return this;
}
public final Builder proxy(Proxy proxy) {
this.proxy = proxy;
return this;
}
public final List<Interceptor> networkInterceptors() {
return this.networkInterceptors;
}
public final List<Interceptor> interceptors() {
return this.interceptors;
}
public final Builder followSslRedirects(boolean z) {
this.followSslRedirects = z;
return this;
}
public final Builder followRedirects(boolean z) {
this.followRedirects = z;
return this;
}
public final Builder cache(Cache cache) {
this.aim = cache;
this.agE = null;
return this;
}
final void a(InternalCache internalCache) {
this.agE = internalCache;
this.aim = null;
}
}
public int writeTimeoutMillis() {
return this.writeTimeout;
}
public SSLSocketFactory sslSocketFactory() {
return this.sslSocketFactory;
}
public SocketFactory socketFactory() {
return this.socketFactory;
}
public boolean retryOnConnectionFailure() {
return this.retryOnConnectionFailure;
}
public int readTimeoutMillis() {
return this.readTimeout;
}
public ProxySelector proxySelector() {
return this.proxySelector;
}
public Authenticator proxyAuthenticator() {
return this.agy;
}
public Proxy proxy() {
return this.proxy;
}
public List<Protocol> protocols() {
return this.protocols;
}
public List<Interceptor> networkInterceptors() {
return this.networkInterceptors;
}
public List<Interceptor> interceptors() {
return this.interceptors;
}
public HostnameVerifier hostnameVerifier() {
return this.hostnameVerifier;
}
public boolean followSslRedirects() {
return this.followSslRedirects;
}
public boolean followRedirects() {
return this.followRedirects;
}
public Dns dns() {
return this.agx;
}
public Dispatcher dispatcher() {
return this.aik;
}
public CookieJar cookieJar() {
return this.ail;
}
public List<ConnectionSpec> connectionSpecs() {
return this.connectionSpecs;
}
public ConnectionPool connectionPool() {
return this.aio;
}
public int connectTimeoutMillis() {
return this.connectTimeout;
}
public CertificatePinner certificatePinner() {
return this.agz;
}
public Cache cache() {
return this.aim;
}
public Authenticator authenticator() {
return this.ain;
}
}