package com.mbridge.msdk.thrid.okhttp; import com.mbridge.msdk.thrid.okhttp.Call; import com.mbridge.msdk.thrid.okhttp.EventListener; import com.mbridge.msdk.thrid.okhttp.Headers; import com.mbridge.msdk.thrid.okhttp.Response; import com.mbridge.msdk.thrid.okhttp.WebSocket; import com.mbridge.msdk.thrid.okhttp.internal.Internal; import com.mbridge.msdk.thrid.okhttp.internal.Util; import com.mbridge.msdk.thrid.okhttp.internal.cache.InternalCache; import com.mbridge.msdk.thrid.okhttp.internal.connection.RealConnection; import com.mbridge.msdk.thrid.okhttp.internal.connection.RouteDatabase; import com.mbridge.msdk.thrid.okhttp.internal.connection.StreamAllocation; import com.mbridge.msdk.thrid.okhttp.internal.platform.Platform; import com.mbridge.msdk.thrid.okhttp.internal.proxy.NullProxySelector; import com.mbridge.msdk.thrid.okhttp.internal.tls.CertificateChainCleaner; import com.mbridge.msdk.thrid.okhttp.internal.tls.OkHostnameVerifier; import com.mbridge.msdk.thrid.okhttp.internal.ws.RealWebSocket; import java.io.IOException; import java.net.Proxy; import java.net.ProxySelector; import java.net.Socket; import java.security.GeneralSecurityException; import java.time.Duration; import java.util.ArrayList; import java.util.Collections; import java.util.Iterator; import java.util.List; import java.util.Random; 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.TrustManager; import javax.net.ssl.X509TrustManager; /* loaded from: classes4.dex */ public class OkHttpClient implements Cloneable, Call.Factory, WebSocket.Factory { final Authenticator authenticator; final Cache cache; final int callTimeout; final CertificateChainCleaner certificateChainCleaner; final CertificatePinner certificatePinner; final int connectTimeout; final ConnectionPool connectionPool; final List connectionSpecs; final CookieJar cookieJar; final Dispatcher dispatcher; final Dns dns; final EventListener.Factory eventListenerFactory; final boolean followRedirects; final boolean followSslRedirects; final HostnameVerifier hostnameVerifier; final List interceptors; final InternalCache internalCache; final List networkInterceptors; final int pingInterval; final List protocols; final Proxy proxy; final Authenticator proxyAuthenticator; final ProxySelector proxySelector; final int readTimeout; final boolean retryOnConnectionFailure; final SocketFactory socketFactory; final SSLSocketFactory sslSocketFactory; final int writeTimeout; static final List DEFAULT_PROTOCOLS = Util.immutableList(Protocol.HTTP_2, Protocol.HTTP_1_1); static final List DEFAULT_CONNECTION_SPECS = Util.immutableList(ConnectionSpec.MODERN_TLS, ConnectionSpec.CLEARTEXT); public Authenticator authenticator() { return this.authenticator; } public Cache cache() { return this.cache; } public int callTimeoutMillis() { return this.callTimeout; } public CertificatePinner certificatePinner() { return this.certificatePinner; } public int connectTimeoutMillis() { return this.connectTimeout; } public ConnectionPool connectionPool() { return this.connectionPool; } public List connectionSpecs() { return this.connectionSpecs; } public CookieJar cookieJar() { return this.cookieJar; } public Dispatcher dispatcher() { return this.dispatcher; } public Dns dns() { return this.dns; } public EventListener.Factory eventListenerFactory() { return this.eventListenerFactory; } public boolean followRedirects() { return this.followRedirects; } public boolean followSslRedirects() { return this.followSslRedirects; } public HostnameVerifier hostnameVerifier() { return this.hostnameVerifier; } public List interceptors() { return this.interceptors; } public List networkInterceptors() { return this.networkInterceptors; } public int pingIntervalMillis() { return this.pingInterval; } public List protocols() { return this.protocols; } public Proxy proxy() { return this.proxy; } public Authenticator proxyAuthenticator() { return this.proxyAuthenticator; } public ProxySelector proxySelector() { return this.proxySelector; } public int readTimeoutMillis() { return this.readTimeout; } public boolean retryOnConnectionFailure() { return this.retryOnConnectionFailure; } public SocketFactory socketFactory() { return this.socketFactory; } public SSLSocketFactory sslSocketFactory() { return this.sslSocketFactory; } public int writeTimeoutMillis() { return this.writeTimeout; } static { Internal.instance = new Internal() { // from class: com.mbridge.msdk.thrid.okhttp.OkHttpClient.1 @Override // com.mbridge.msdk.thrid.okhttp.internal.Internal public void addLenient(Headers.Builder builder, String str) { builder.addLenient(str); } @Override // com.mbridge.msdk.thrid.okhttp.internal.Internal public void addLenient(Headers.Builder builder, String str, String str2) { builder.addLenient(str, str2); } @Override // com.mbridge.msdk.thrid.okhttp.internal.Internal public void setCache(Builder builder, InternalCache internalCache) { builder.setInternalCache(internalCache); } @Override // com.mbridge.msdk.thrid.okhttp.internal.Internal public boolean connectionBecameIdle(ConnectionPool connectionPool, RealConnection realConnection) { return connectionPool.connectionBecameIdle(realConnection); } @Override // com.mbridge.msdk.thrid.okhttp.internal.Internal public RealConnection get(ConnectionPool connectionPool, Address address, StreamAllocation streamAllocation, Route route) { return connectionPool.get(address, streamAllocation, route); } @Override // com.mbridge.msdk.thrid.okhttp.internal.Internal public boolean equalsNonHost(Address address, Address address2) { return address.equalsNonHost(address2); } @Override // com.mbridge.msdk.thrid.okhttp.internal.Internal public Socket deduplicate(ConnectionPool connectionPool, Address address, StreamAllocation streamAllocation) { return connectionPool.deduplicate(address, streamAllocation); } @Override // com.mbridge.msdk.thrid.okhttp.internal.Internal public void put(ConnectionPool connectionPool, RealConnection realConnection) { connectionPool.put(realConnection); } @Override // com.mbridge.msdk.thrid.okhttp.internal.Internal public RouteDatabase routeDatabase(ConnectionPool connectionPool) { return connectionPool.routeDatabase; } @Override // com.mbridge.msdk.thrid.okhttp.internal.Internal public int code(Response.Builder builder) { return builder.code; } @Override // com.mbridge.msdk.thrid.okhttp.internal.Internal public void apply(ConnectionSpec connectionSpec, SSLSocket sSLSocket, boolean z) { connectionSpec.apply(sSLSocket, z); } @Override // com.mbridge.msdk.thrid.okhttp.internal.Internal public boolean isInvalidHttpUrlHost(IllegalArgumentException illegalArgumentException) { return illegalArgumentException.getMessage().startsWith("Invalid URL host"); } @Override // com.mbridge.msdk.thrid.okhttp.internal.Internal public StreamAllocation streamAllocation(Call call) { return ((RealCall) call).streamAllocation(); } @Override // com.mbridge.msdk.thrid.okhttp.internal.Internal public IOException timeoutExit(Call call, IOException iOException) { return ((RealCall) call).timeoutExit(iOException); } @Override // com.mbridge.msdk.thrid.okhttp.internal.Internal public Call newWebSocketCall(OkHttpClient okHttpClient, Request request) { return RealCall.newRealCall(okHttpClient, request, true); } }; } public OkHttpClient() { this(new Builder()); } public OkHttpClient(Builder builder) { boolean z; this.dispatcher = builder.dispatcher; this.proxy = builder.proxy; this.protocols = builder.protocols; List list = builder.connectionSpecs; this.connectionSpecs = list; this.interceptors = Util.immutableList(builder.interceptors); this.networkInterceptors = Util.immutableList(builder.networkInterceptors); this.eventListenerFactory = builder.eventListenerFactory; this.proxySelector = builder.proxySelector; this.cookieJar = builder.cookieJar; this.cache = builder.cache; this.internalCache = builder.internalCache; this.socketFactory = builder.socketFactory; Iterator it = list.iterator(); loop0: while (true) { z = false; while (it.hasNext()) { z = (z || it.next().isTls()) ? true : z; } } SSLSocketFactory sSLSocketFactory = builder.sslSocketFactory; if (sSLSocketFactory != null || !z) { this.sslSocketFactory = sSLSocketFactory; this.certificateChainCleaner = builder.certificateChainCleaner; } else { X509TrustManager platformTrustManager = Util.platformTrustManager(); this.sslSocketFactory = newSslSocketFactory(platformTrustManager); this.certificateChainCleaner = CertificateChainCleaner.get(platformTrustManager); } if (this.sslSocketFactory != null) { Platform.get().configureSslSocketFactory(this.sslSocketFactory); } this.hostnameVerifier = builder.hostnameVerifier; this.certificatePinner = builder.certificatePinner.withCertificateChainCleaner(this.certificateChainCleaner); this.proxyAuthenticator = builder.proxyAuthenticator; this.authenticator = builder.authenticator; this.connectionPool = builder.connectionPool; this.dns = builder.dns; this.followSslRedirects = builder.followSslRedirects; this.followRedirects = builder.followRedirects; this.retryOnConnectionFailure = builder.retryOnConnectionFailure; this.callTimeout = builder.callTimeout; this.connectTimeout = builder.connectTimeout; this.readTimeout = builder.readTimeout; this.writeTimeout = builder.writeTimeout; this.pingInterval = builder.pingInterval; if (this.interceptors.contains(null)) { throw new IllegalStateException("Null interceptor: " + this.interceptors); } if (this.networkInterceptors.contains(null)) { throw new IllegalStateException("Null network interceptor: " + this.networkInterceptors); } } private static SSLSocketFactory newSslSocketFactory(X509TrustManager x509TrustManager) { try { SSLContext sSLContext = Platform.get().getSSLContext(); sSLContext.init(null, new TrustManager[]{x509TrustManager}, null); return sSLContext.getSocketFactory(); } catch (GeneralSecurityException e) { throw Util.assertionError("No System TLS", e); } } public InternalCache internalCache() { Cache cache = this.cache; return cache != null ? cache.internalCache : this.internalCache; } @Override // com.mbridge.msdk.thrid.okhttp.Call.Factory public Call newCall(Request request) { return RealCall.newRealCall(this, request, false); } @Override // com.mbridge.msdk.thrid.okhttp.WebSocket.Factory public WebSocket newWebSocket(Request request, WebSocketListener webSocketListener) { RealWebSocket realWebSocket = new RealWebSocket(request, webSocketListener, new Random(), this.pingInterval); realWebSocket.connect(this); return realWebSocket; } public Builder newBuilder() { return new Builder(this); } public static final class Builder { Authenticator authenticator; Cache cache; int callTimeout; CertificateChainCleaner certificateChainCleaner; CertificatePinner certificatePinner; int connectTimeout; ConnectionPool connectionPool; List connectionSpecs; CookieJar cookieJar; Dispatcher dispatcher; Dns dns; EventListener.Factory eventListenerFactory; boolean followRedirects; boolean followSslRedirects; HostnameVerifier hostnameVerifier; final List interceptors; InternalCache internalCache; final List networkInterceptors; int pingInterval; List protocols; Proxy proxy; Authenticator proxyAuthenticator; ProxySelector proxySelector; int readTimeout; boolean retryOnConnectionFailure; SocketFactory socketFactory; SSLSocketFactory sslSocketFactory; int writeTimeout; public Builder cache(Cache cache) { this.cache = cache; this.internalCache = null; return this; } public Builder followRedirects(boolean z) { this.followRedirects = z; return this; } public Builder followSslRedirects(boolean z) { this.followSslRedirects = z; return this; } public List interceptors() { return this.interceptors; } public List networkInterceptors() { return this.networkInterceptors; } public Builder proxy(Proxy proxy) { this.proxy = proxy; return this; } public Builder retryOnConnectionFailure(boolean z) { this.retryOnConnectionFailure = z; return this; } public void setInternalCache(InternalCache internalCache) { this.internalCache = internalCache; this.cache = null; } public Builder() { this.interceptors = new ArrayList(); this.networkInterceptors = new ArrayList(); this.dispatcher = new Dispatcher(); this.protocols = OkHttpClient.DEFAULT_PROTOCOLS; this.connectionSpecs = OkHttpClient.DEFAULT_CONNECTION_SPECS; this.eventListenerFactory = EventListener.factory(EventListener.NONE); ProxySelector proxySelector = ProxySelector.getDefault(); this.proxySelector = proxySelector; if (proxySelector == null) { this.proxySelector = new NullProxySelector(); } this.cookieJar = CookieJar.NO_COOKIES; this.socketFactory = SocketFactory.getDefault(); this.hostnameVerifier = OkHostnameVerifier.INSTANCE; this.certificatePinner = CertificatePinner.DEFAULT; Authenticator authenticator = Authenticator.NONE; this.proxyAuthenticator = authenticator; this.authenticator = authenticator; this.connectionPool = new ConnectionPool(); this.dns = Dns.SYSTEM; this.followSslRedirects = true; this.followRedirects = true; this.retryOnConnectionFailure = true; this.callTimeout = 0; this.connectTimeout = 10000; this.readTimeout = 10000; this.writeTimeout = 10000; this.pingInterval = 0; } public Builder(OkHttpClient okHttpClient) { ArrayList arrayList = new ArrayList(); this.interceptors = arrayList; ArrayList arrayList2 = new ArrayList(); this.networkInterceptors = arrayList2; this.dispatcher = okHttpClient.dispatcher; this.proxy = okHttpClient.proxy; this.protocols = okHttpClient.protocols; this.connectionSpecs = okHttpClient.connectionSpecs; arrayList.addAll(okHttpClient.interceptors); arrayList2.addAll(okHttpClient.networkInterceptors); this.eventListenerFactory = okHttpClient.eventListenerFactory; this.proxySelector = okHttpClient.proxySelector; this.cookieJar = okHttpClient.cookieJar; this.internalCache = okHttpClient.internalCache; this.cache = okHttpClient.cache; this.socketFactory = okHttpClient.socketFactory; this.sslSocketFactory = okHttpClient.sslSocketFactory; this.certificateChainCleaner = okHttpClient.certificateChainCleaner; this.hostnameVerifier = okHttpClient.hostnameVerifier; this.certificatePinner = okHttpClient.certificatePinner; this.proxyAuthenticator = okHttpClient.proxyAuthenticator; this.authenticator = okHttpClient.authenticator; this.connectionPool = okHttpClient.connectionPool; this.dns = okHttpClient.dns; this.followSslRedirects = okHttpClient.followSslRedirects; this.followRedirects = okHttpClient.followRedirects; this.retryOnConnectionFailure = okHttpClient.retryOnConnectionFailure; this.callTimeout = okHttpClient.callTimeout; this.connectTimeout = okHttpClient.connectTimeout; this.readTimeout = okHttpClient.readTimeout; this.writeTimeout = okHttpClient.writeTimeout; this.pingInterval = okHttpClient.pingInterval; } public Builder callTimeout(long j, TimeUnit timeUnit) { this.callTimeout = Util.checkDuration("timeout", j, timeUnit); return this; } public Builder callTimeout(Duration duration) { this.callTimeout = Util.checkDuration("timeout", duration.toMillis(), TimeUnit.MILLISECONDS); return this; } public Builder connectTimeout(long j, TimeUnit timeUnit) { this.connectTimeout = Util.checkDuration("timeout", j, timeUnit); return this; } public Builder connectTimeout(Duration duration) { this.connectTimeout = Util.checkDuration("timeout", duration.toMillis(), TimeUnit.MILLISECONDS); return this; } public Builder readTimeout(long j, TimeUnit timeUnit) { this.readTimeout = Util.checkDuration("timeout", j, timeUnit); return this; } public Builder readTimeout(Duration duration) { this.readTimeout = Util.checkDuration("timeout", duration.toMillis(), TimeUnit.MILLISECONDS); return this; } public Builder writeTimeout(long j, TimeUnit timeUnit) { this.writeTimeout = Util.checkDuration("timeout", j, timeUnit); return this; } public Builder writeTimeout(Duration duration) { this.writeTimeout = Util.checkDuration("timeout", duration.toMillis(), TimeUnit.MILLISECONDS); return this; } public Builder pingInterval(long j, TimeUnit timeUnit) { this.pingInterval = Util.checkDuration("interval", j, timeUnit); return this; } public Builder pingInterval(Duration duration) { this.pingInterval = Util.checkDuration("timeout", duration.toMillis(), TimeUnit.MILLISECONDS); return this; } public Builder proxySelector(ProxySelector proxySelector) { if (proxySelector == null) { throw new NullPointerException("proxySelector == null"); } this.proxySelector = proxySelector; return this; } public Builder cookieJar(CookieJar cookieJar) { if (cookieJar == null) { throw new NullPointerException("cookieJar == null"); } this.cookieJar = cookieJar; return this; } public Builder dns(Dns dns) { if (dns == null) { throw new NullPointerException("dns == null"); } this.dns = dns; return this; } public Builder socketFactory(SocketFactory socketFactory) { if (socketFactory == null) { throw new NullPointerException("socketFactory == null"); } this.socketFactory = socketFactory; return this; } public Builder sslSocketFactory(SSLSocketFactory sSLSocketFactory) { if (sSLSocketFactory == null) { throw new NullPointerException("sslSocketFactory == null"); } this.sslSocketFactory = sSLSocketFactory; this.certificateChainCleaner = Platform.get().buildCertificateChainCleaner(sSLSocketFactory); return this; } public Builder sslSocketFactory(SSLSocketFactory sSLSocketFactory, X509TrustManager x509TrustManager) { if (sSLSocketFactory == null) { throw new NullPointerException("sslSocketFactory == null"); } if (x509TrustManager == null) { throw new NullPointerException("trustManager == null"); } this.sslSocketFactory = sSLSocketFactory; this.certificateChainCleaner = CertificateChainCleaner.get(x509TrustManager); return this; } public Builder hostnameVerifier(HostnameVerifier hostnameVerifier) { if (hostnameVerifier == null) { throw new NullPointerException("hostnameVerifier == null"); } this.hostnameVerifier = hostnameVerifier; return this; } public Builder certificatePinner(CertificatePinner certificatePinner) { if (certificatePinner == null) { throw new NullPointerException("certificatePinner == null"); } this.certificatePinner = certificatePinner; return this; } public Builder authenticator(Authenticator authenticator) { if (authenticator == null) { throw new NullPointerException("authenticator == null"); } this.authenticator = authenticator; return this; } public Builder proxyAuthenticator(Authenticator authenticator) { if (authenticator == null) { throw new NullPointerException("proxyAuthenticator == null"); } this.proxyAuthenticator = authenticator; return this; } public Builder connectionPool(ConnectionPool connectionPool) { if (connectionPool == null) { throw new NullPointerException("connectionPool == null"); } this.connectionPool = connectionPool; return this; } public Builder dispatcher(Dispatcher dispatcher) { if (dispatcher == null) { throw new IllegalArgumentException("dispatcher == null"); } this.dispatcher = dispatcher; return this; } public Builder protocols(List list) { ArrayList arrayList = new ArrayList(list); Protocol protocol = Protocol.H2_PRIOR_KNOWLEDGE; if (!arrayList.contains(protocol) && !arrayList.contains(Protocol.HTTP_1_1)) { throw new IllegalArgumentException("protocols must contain h2_prior_knowledge or http/1.1: " + arrayList); } if (arrayList.contains(protocol) && arrayList.size() > 1) { throw new IllegalArgumentException("protocols containing h2_prior_knowledge cannot use other protocols: " + arrayList); } if (arrayList.contains(Protocol.HTTP_1_0)) { throw new IllegalArgumentException("protocols must not contain http/1.0: " + arrayList); } if (arrayList.contains(null)) { throw new IllegalArgumentException("protocols must not contain null"); } arrayList.remove(Protocol.SPDY_3); this.protocols = Collections.unmodifiableList(arrayList); return this; } public Builder connectionSpecs(List list) { this.connectionSpecs = Util.immutableList(list); return this; } public Builder addInterceptor(Interceptor interceptor) { if (interceptor == null) { throw new IllegalArgumentException("interceptor == null"); } this.interceptors.add(interceptor); return this; } public Builder addNetworkInterceptor(Interceptor interceptor) { if (interceptor == null) { throw new IllegalArgumentException("interceptor == null"); } this.networkInterceptors.add(interceptor); return this; } public Builder eventListener(EventListener eventListener) { if (eventListener == null) { throw new NullPointerException("eventListener == null"); } this.eventListenerFactory = EventListener.factory(eventListener); return this; } public Builder eventListenerFactory(EventListener.Factory factory) { if (factory == null) { throw new NullPointerException("eventListenerFactory == null"); } this.eventListenerFactory = factory; return this; } public OkHttpClient build() { return new OkHttpClient(this); } } }