Initial commit

This commit is contained in:
2025-05-13 19:24:51 +02:00
commit a950f49678
10604 changed files with 932663 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
package okhttp3.internal.http;
import java.io.IOException;
import java.util.List;
import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.internal.Util;
import okhttp3.internal.Version;
import okio.GzipSource;
import okio.Okio;
/* loaded from: classes2.dex */
public final class BridgeInterceptor implements Interceptor {
private final CookieJar cookieJar;
public BridgeInterceptor(CookieJar cookieJar) {
this.cookieJar = cookieJar;
}
private String cookieHeader(List<Cookie> list) {
StringBuilder sb = new StringBuilder();
int size = list.size();
for (int i = 0; i < size; i++) {
if (i > 0) {
sb.append("; ");
}
Cookie cookie = list.get(i);
sb.append(cookie.name());
sb.append('=');
sb.append(cookie.value());
}
return sb.toString();
}
@Override // okhttp3.Interceptor
public Response intercept(Interceptor.Chain chain) throws IOException {
Request request = chain.request();
Request.Builder newBuilder = request.newBuilder();
RequestBody body = request.body();
if (body != null) {
MediaType contentType = body.contentType();
if (contentType != null) {
newBuilder.header("Content-Type", contentType.toString());
}
long contentLength = body.contentLength();
if (contentLength != -1) {
newBuilder.header("Content-Length", Long.toString(contentLength));
newBuilder.removeHeader("Transfer-Encoding");
} else {
newBuilder.header("Transfer-Encoding", "chunked");
newBuilder.removeHeader("Content-Length");
}
}
boolean z = false;
if (request.header("Host") == null) {
newBuilder.header("Host", Util.hostHeader(request.url(), false));
}
if (request.header("Connection") == null) {
newBuilder.header("Connection", "Keep-Alive");
}
if (request.header("Accept-Encoding") == null && request.header("Range") == null) {
z = true;
newBuilder.header("Accept-Encoding", "gzip");
}
List<Cookie> loadForRequest = this.cookieJar.loadForRequest(request.url());
if (!loadForRequest.isEmpty()) {
newBuilder.header("Cookie", cookieHeader(loadForRequest));
}
if (request.header("User-Agent") == null) {
newBuilder.header("User-Agent", Version.userAgent());
}
Response proceed = chain.proceed(newBuilder.build());
HttpHeaders.receiveHeaders(this.cookieJar, request.url(), proceed.headers());
Response.Builder request2 = proceed.newBuilder().request(request);
if (z && "gzip".equalsIgnoreCase(proceed.header("Content-Encoding")) && HttpHeaders.hasBody(proceed)) {
GzipSource gzipSource = new GzipSource(proceed.body().source());
request2.headers(proceed.headers().newBuilder().removeAll("Content-Encoding").removeAll("Content-Length").build());
request2.body(new RealResponseBody(proceed.header("Content-Type"), -1L, Okio.buffer(gzipSource)));
}
return request2.build();
}
}

View File

@@ -0,0 +1,89 @@
package okhttp3.internal.http;
import java.io.IOException;
import java.net.ProtocolException;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.internal.Util;
import okhttp3.internal.connection.RealConnection;
import okhttp3.internal.connection.StreamAllocation;
import okio.Buffer;
import okio.BufferedSink;
import okio.ForwardingSink;
import okio.Okio;
import okio.Sink;
/* loaded from: classes2.dex */
public final class CallServerInterceptor implements Interceptor {
private final boolean forWebSocket;
static final class CountingSink extends ForwardingSink {
long successfulCount;
CountingSink(Sink sink) {
super(sink);
}
@Override // okio.ForwardingSink, okio.Sink
public void write(Buffer buffer, long j) throws IOException {
super.write(buffer, j);
this.successfulCount += j;
}
}
public CallServerInterceptor(boolean z) {
this.forWebSocket = z;
}
@Override // okhttp3.Interceptor
public Response intercept(Interceptor.Chain chain) throws IOException {
RealInterceptorChain realInterceptorChain = (RealInterceptorChain) chain;
HttpCodec httpStream = realInterceptorChain.httpStream();
StreamAllocation streamAllocation = realInterceptorChain.streamAllocation();
RealConnection realConnection = (RealConnection) realInterceptorChain.connection();
Request request = realInterceptorChain.request();
long currentTimeMillis = System.currentTimeMillis();
realInterceptorChain.eventListener().requestHeadersStart(realInterceptorChain.call());
httpStream.writeRequestHeaders(request);
realInterceptorChain.eventListener().requestHeadersEnd(realInterceptorChain.call(), request);
Response.Builder builder = null;
if (HttpMethod.permitsRequestBody(request.method()) && request.body() != null) {
if ("100-continue".equalsIgnoreCase(request.header("Expect"))) {
httpStream.flushRequest();
realInterceptorChain.eventListener().responseHeadersStart(realInterceptorChain.call());
builder = httpStream.readResponseHeaders(true);
}
if (builder == null) {
realInterceptorChain.eventListener().requestBodyStart(realInterceptorChain.call());
CountingSink countingSink = new CountingSink(httpStream.createRequestBody(request, request.body().contentLength()));
BufferedSink buffer = Okio.buffer(countingSink);
request.body().writeTo(buffer);
buffer.close();
realInterceptorChain.eventListener().requestBodyEnd(realInterceptorChain.call(), countingSink.successfulCount);
} else if (!realConnection.isMultiplexed()) {
streamAllocation.noNewStreams();
}
}
httpStream.finishRequest();
if (builder == null) {
realInterceptorChain.eventListener().responseHeadersStart(realInterceptorChain.call());
builder = httpStream.readResponseHeaders(false);
}
Response build = builder.request(request).handshake(streamAllocation.connection().handshake()).sentRequestAtMillis(currentTimeMillis).receivedResponseAtMillis(System.currentTimeMillis()).build();
int code = build.code();
if (code == 100) {
build = httpStream.readResponseHeaders(false).request(request).handshake(streamAllocation.connection().handshake()).sentRequestAtMillis(currentTimeMillis).receivedResponseAtMillis(System.currentTimeMillis()).build();
code = build.code();
}
realInterceptorChain.eventListener().responseHeadersEnd(realInterceptorChain.call(), build);
Response build2 = (this.forWebSocket && code == 101) ? build.newBuilder().body(Util.EMPTY_RESPONSE).build() : build.newBuilder().body(httpStream.openResponseBody(build)).build();
if ("close".equalsIgnoreCase(build2.request().header("Connection")) || "close".equalsIgnoreCase(build2.header("Connection"))) {
streamAllocation.noNewStreams();
}
if ((code != 204 && code != 205) || build2.body().contentLength() <= 0) {
return build2;
}
throw new ProtocolException("HTTP " + code + " had non-zero Content-Length: " + build2.body().contentLength());
}
}

View File

@@ -0,0 +1,26 @@
package okhttp3.internal.http;
import java.io.IOException;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okio.Sink;
/* loaded from: classes2.dex */
public interface HttpCodec {
public static final int DISCARD_STREAM_TIMEOUT_MILLIS = 100;
void cancel();
Sink createRequestBody(Request request, long j);
void finishRequest() throws IOException;
void flushRequest() throws IOException;
ResponseBody openResponseBody(Response response) throws IOException;
Response.Builder readResponseHeaders(boolean z) throws IOException;
void writeRequestHeaders(Request request) throws IOException;
}

View File

@@ -0,0 +1,60 @@
package okhttp3.internal.http;
import java.text.DateFormat;
import java.text.ParsePosition;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import okhttp3.internal.Util;
/* loaded from: classes2.dex */
public final class HttpDate {
public static final long MAX_DATE = 253402300799999L;
private static final ThreadLocal<DateFormat> STANDARD_DATE_FORMAT = new ThreadLocal<DateFormat>() { // from class: okhttp3.internal.http.HttpDate.1
/* JADX INFO: Access modifiers changed from: protected */
@Override // java.lang.ThreadLocal
public DateFormat initialValue() {
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss 'GMT'", Locale.US);
simpleDateFormat.setLenient(false);
simpleDateFormat.setTimeZone(Util.UTC);
return simpleDateFormat;
}
};
private static final String[] BROWSER_COMPATIBLE_DATE_FORMAT_STRINGS = {"EEE, dd MMM yyyy HH:mm:ss zzz", "EEEE, dd-MMM-yy HH:mm:ss zzz", "EEE MMM d HH:mm:ss yyyy", "EEE, dd-MMM-yyyy HH:mm:ss z", "EEE, dd-MMM-yyyy HH-mm-ss z", "EEE, dd MMM yy HH:mm:ss z", "EEE dd-MMM-yyyy HH:mm:ss z", "EEE dd MMM yyyy HH:mm:ss z", "EEE dd-MMM-yyyy HH-mm-ss z", "EEE dd-MMM-yy HH:mm:ss z", "EEE dd MMM yy HH:mm:ss z", "EEE,dd-MMM-yy HH:mm:ss z", "EEE,dd-MMM-yyyy HH:mm:ss z", "EEE, dd-MM-yyyy HH:mm:ss z", "EEE MMM d yyyy HH:mm:ss z"};
private static final DateFormat[] BROWSER_COMPATIBLE_DATE_FORMATS = new DateFormat[BROWSER_COMPATIBLE_DATE_FORMAT_STRINGS.length];
private HttpDate() {
}
public static String format(Date date) {
return STANDARD_DATE_FORMAT.get().format(date);
}
public static Date parse(String str) {
if (str.length() == 0) {
return null;
}
ParsePosition parsePosition = new ParsePosition(0);
Date parse = STANDARD_DATE_FORMAT.get().parse(str, parsePosition);
if (parsePosition.getIndex() == str.length()) {
return parse;
}
synchronized (BROWSER_COMPATIBLE_DATE_FORMAT_STRINGS) {
int length = BROWSER_COMPATIBLE_DATE_FORMAT_STRINGS.length;
for (int i = 0; i < length; i++) {
DateFormat dateFormat = BROWSER_COMPATIBLE_DATE_FORMATS[i];
if (dateFormat == null) {
dateFormat = new SimpleDateFormat(BROWSER_COMPATIBLE_DATE_FORMAT_STRINGS[i], Locale.US);
dateFormat.setTimeZone(Util.UTC);
BROWSER_COMPATIBLE_DATE_FORMATS[i] = dateFormat;
}
parsePosition.setIndex(0);
Date parse2 = dateFormat.parse(str, parsePosition);
if (parsePosition.getIndex() != 0) {
return parse2;
}
}
return null;
}
}
}

View File

@@ -0,0 +1,189 @@
package okhttp3.internal.http;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import okhttp3.Challenge;
import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.internal.Util;
/* loaded from: classes2.dex */
public final class HttpHeaders {
private static final Pattern PARAMETER = Pattern.compile(" +([^ \"=]*)=(:?\"([^\"]*)\"|([^ \"=]*)) *(:?,|$)");
private static final String QUOTED_STRING = "\"([^\"]*)\"";
private static final String TOKEN = "([^ \"=]*)";
private HttpHeaders() {
}
public static long contentLength(Response response) {
return contentLength(response.headers());
}
public static boolean hasBody(Response response) {
if (response.request().method().equals("HEAD")) {
return false;
}
int code = response.code();
return (((code >= 100 && code < 200) || code == 204 || code == 304) && contentLength(response) == -1 && !"chunked".equalsIgnoreCase(response.header("Transfer-Encoding"))) ? false : true;
}
public static boolean hasVaryAll(Response response) {
return hasVaryAll(response.headers());
}
public static List<Challenge> parseChallenges(Headers headers, String str) {
ArrayList arrayList = new ArrayList();
for (String str2 : headers.values(str)) {
int indexOf = str2.indexOf(32);
if (indexOf != -1) {
String substring = str2.substring(0, indexOf);
Matcher matcher = PARAMETER.matcher(str2);
String str3 = null;
String str4 = null;
while (matcher.find(indexOf)) {
if (str2.regionMatches(true, matcher.start(1), "realm", 0, 5)) {
str3 = matcher.group(3);
} else if (str2.regionMatches(true, matcher.start(1), "charset", 0, 7)) {
str4 = matcher.group(3);
}
if (str3 != null && str4 != null) {
break;
}
indexOf = matcher.end();
}
if (str3 != null) {
Challenge challenge = new Challenge(substring, str3);
if (str4 != null) {
if (str4.equalsIgnoreCase("UTF-8")) {
challenge = challenge.withCharset(Util.UTF_8);
}
}
arrayList.add(challenge);
}
}
}
return arrayList;
}
public static int parseSeconds(String str, int i) {
try {
long parseLong = Long.parseLong(str);
if (parseLong > 2147483647L) {
return Integer.MAX_VALUE;
}
if (parseLong < 0) {
return 0;
}
return (int) parseLong;
} catch (NumberFormatException unused) {
return i;
}
}
public static void receiveHeaders(CookieJar cookieJar, HttpUrl httpUrl, Headers headers) {
if (cookieJar == CookieJar.NO_COOKIES) {
return;
}
List<Cookie> parseAll = Cookie.parseAll(httpUrl, headers);
if (parseAll.isEmpty()) {
return;
}
cookieJar.saveFromResponse(httpUrl, parseAll);
}
public static int skipUntil(String str, int i, String str2) {
while (i < str.length() && str2.indexOf(str.charAt(i)) == -1) {
i++;
}
return i;
}
public static int skipWhitespace(String str, int i) {
char charAt;
while (i < str.length() && ((charAt = str.charAt(i)) == ' ' || charAt == '\t')) {
i++;
}
return i;
}
private static long stringToLong(String str) {
if (str == null) {
return -1L;
}
try {
return Long.parseLong(str);
} catch (NumberFormatException unused) {
return -1L;
}
}
private static Set<String> varyFields(Response response) {
return varyFields(response.headers());
}
public static Headers varyHeaders(Response response) {
return varyHeaders(response.networkResponse().request().headers(), response.headers());
}
public static boolean varyMatches(Response response, Headers headers, Request request) {
for (String str : varyFields(response)) {
if (!Util.equal(headers.values(str), request.headers(str))) {
return false;
}
}
return true;
}
public static long contentLength(Headers headers) {
return stringToLong(headers.get("Content-Length"));
}
public static boolean hasVaryAll(Headers headers) {
return varyFields(headers).contains("*");
}
public static Set<String> varyFields(Headers headers) {
Set<String> emptySet = Collections.emptySet();
int size = headers.size();
Set<String> set = emptySet;
for (int i = 0; i < size; i++) {
if ("Vary".equalsIgnoreCase(headers.name(i))) {
String value = headers.value(i);
if (set.isEmpty()) {
set = new TreeSet<>((Comparator<? super String>) String.CASE_INSENSITIVE_ORDER);
}
for (String str : value.split(",")) {
set.add(str.trim());
}
}
}
return set;
}
public static Headers varyHeaders(Headers headers, Headers headers2) {
Set<String> varyFields = varyFields(headers2);
if (varyFields.isEmpty()) {
return new Headers.Builder().build();
}
Headers.Builder builder = new Headers.Builder();
int size = headers.size();
for (int i = 0; i < size; i++) {
String name = headers.name(i);
if (varyFields.contains(name)) {
builder.add(name, headers.value(i));
}
}
return builder.build();
}
}

View File

@@ -0,0 +1,27 @@
package okhttp3.internal.http;
/* loaded from: classes2.dex */
public final class HttpMethod {
private HttpMethod() {
}
public static boolean invalidatesCache(String str) {
return str.equals("POST") || str.equals("PATCH") || str.equals("PUT") || str.equals("DELETE") || str.equals("MOVE");
}
public static boolean permitsRequestBody(String str) {
return (str.equals("GET") || str.equals("HEAD")) ? false : true;
}
public static boolean redirectsToGet(String str) {
return !str.equals("PROPFIND");
}
public static boolean redirectsWithBody(String str) {
return str.equals("PROPFIND");
}
public static boolean requiresRequestBody(String str) {
return str.equals("POST") || str.equals("PUT") || str.equals("PATCH") || str.equals("PROPPATCH") || str.equals("REPORT");
}
}

View File

@@ -0,0 +1,132 @@
package okhttp3.internal.http;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.TimeUnit;
import okhttp3.Call;
import okhttp3.Connection;
import okhttp3.EventListener;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.internal.Util;
import okhttp3.internal.connection.RealConnection;
import okhttp3.internal.connection.StreamAllocation;
/* loaded from: classes2.dex */
public final class RealInterceptorChain implements Interceptor.Chain {
private final Call call;
private int calls;
private final int connectTimeout;
private final RealConnection connection;
private final EventListener eventListener;
private final HttpCodec httpCodec;
private final int index;
private final List<Interceptor> interceptors;
private final int readTimeout;
private final Request request;
private final StreamAllocation streamAllocation;
private final int writeTimeout;
public RealInterceptorChain(List<Interceptor> list, StreamAllocation streamAllocation, HttpCodec httpCodec, RealConnection realConnection, int i, Request request, Call call, EventListener eventListener, int i2, int i3, int i4) {
this.interceptors = list;
this.connection = realConnection;
this.streamAllocation = streamAllocation;
this.httpCodec = httpCodec;
this.index = i;
this.request = request;
this.call = call;
this.eventListener = eventListener;
this.connectTimeout = i2;
this.readTimeout = i3;
this.writeTimeout = i4;
}
@Override // okhttp3.Interceptor.Chain
public Call call() {
return this.call;
}
@Override // okhttp3.Interceptor.Chain
public int connectTimeoutMillis() {
return this.connectTimeout;
}
@Override // okhttp3.Interceptor.Chain
public Connection connection() {
return this.connection;
}
public EventListener eventListener() {
return this.eventListener;
}
public HttpCodec httpStream() {
return this.httpCodec;
}
@Override // okhttp3.Interceptor.Chain
public Response proceed(Request request) throws IOException {
return proceed(request, this.streamAllocation, this.httpCodec, this.connection);
}
@Override // okhttp3.Interceptor.Chain
public int readTimeoutMillis() {
return this.readTimeout;
}
@Override // okhttp3.Interceptor.Chain
public Request request() {
return this.request;
}
public StreamAllocation streamAllocation() {
return this.streamAllocation;
}
@Override // okhttp3.Interceptor.Chain
public Interceptor.Chain withConnectTimeout(int i, TimeUnit timeUnit) {
return new RealInterceptorChain(this.interceptors, this.streamAllocation, this.httpCodec, this.connection, this.index, this.request, this.call, this.eventListener, Util.checkDuration("timeout", i, timeUnit), this.readTimeout, this.writeTimeout);
}
@Override // okhttp3.Interceptor.Chain
public Interceptor.Chain withReadTimeout(int i, TimeUnit timeUnit) {
return new RealInterceptorChain(this.interceptors, this.streamAllocation, this.httpCodec, this.connection, this.index, this.request, this.call, this.eventListener, this.connectTimeout, Util.checkDuration("timeout", i, timeUnit), this.writeTimeout);
}
@Override // okhttp3.Interceptor.Chain
public Interceptor.Chain withWriteTimeout(int i, TimeUnit timeUnit) {
return new RealInterceptorChain(this.interceptors, this.streamAllocation, this.httpCodec, this.connection, this.index, this.request, this.call, this.eventListener, this.connectTimeout, this.readTimeout, Util.checkDuration("timeout", i, timeUnit));
}
@Override // okhttp3.Interceptor.Chain
public int writeTimeoutMillis() {
return this.writeTimeout;
}
public Response proceed(Request request, StreamAllocation streamAllocation, HttpCodec httpCodec, RealConnection realConnection) throws IOException {
if (this.index >= this.interceptors.size()) {
throw new AssertionError();
}
this.calls++;
if (this.httpCodec != null && !this.connection.supportsUrl(request.url())) {
throw new IllegalStateException("network interceptor " + this.interceptors.get(this.index - 1) + " must retain the same host and port");
}
if (this.httpCodec != null && this.calls > 1) {
throw new IllegalStateException("network interceptor " + this.interceptors.get(this.index - 1) + " must call proceed() exactly once");
}
RealInterceptorChain realInterceptorChain = new RealInterceptorChain(this.interceptors, streamAllocation, httpCodec, realConnection, this.index + 1, request, this.call, this.eventListener, this.connectTimeout, this.readTimeout, this.writeTimeout);
Interceptor interceptor = this.interceptors.get(this.index);
Response intercept = interceptor.intercept(realInterceptorChain);
if (httpCodec != null && this.index + 1 < this.interceptors.size() && realInterceptorChain.calls != 1) {
throw new IllegalStateException("network interceptor " + interceptor + " must call proceed() exactly once");
}
if (intercept == null) {
throw new NullPointerException("interceptor " + interceptor + " returned null");
}
if (intercept.body() != null) {
return intercept;
}
throw new IllegalStateException("interceptor " + interceptor + " returned a response with no body");
}
}

View File

@@ -0,0 +1,37 @@
package okhttp3.internal.http;
import okhttp3.MediaType;
import okhttp3.ResponseBody;
import okio.BufferedSource;
/* loaded from: classes2.dex */
public final class RealResponseBody extends ResponseBody {
private final long contentLength;
private final String contentTypeString;
private final BufferedSource source;
public RealResponseBody(String str, long j, BufferedSource bufferedSource) {
this.contentTypeString = str;
this.contentLength = j;
this.source = bufferedSource;
}
@Override // okhttp3.ResponseBody
public long contentLength() {
return this.contentLength;
}
@Override // okhttp3.ResponseBody
public MediaType contentType() {
String str = this.contentTypeString;
if (str != null) {
return MediaType.parse(str);
}
return null;
}
@Override // okhttp3.ResponseBody
public BufferedSource source() {
return this.source;
}
}

View File

@@ -0,0 +1,37 @@
package okhttp3.internal.http;
import java.net.Proxy;
import okhttp3.HttpUrl;
import okhttp3.Request;
/* loaded from: classes2.dex */
public final class RequestLine {
private RequestLine() {
}
public static String get(Request request, Proxy.Type type) {
StringBuilder sb = new StringBuilder();
sb.append(request.method());
sb.append(' ');
if (includeAuthorityInRequestLine(request, type)) {
sb.append(request.url());
} else {
sb.append(requestPath(request.url()));
}
sb.append(" HTTP/1.1");
return sb.toString();
}
private static boolean includeAuthorityInRequestLine(Request request, Proxy.Type type) {
return !request.isHttps() && type == Proxy.Type.HTTP;
}
public static String requestPath(HttpUrl httpUrl) {
String encodedPath = httpUrl.encodedPath();
String encodedQuery = httpUrl.encodedQuery();
if (encodedQuery == null) {
return encodedPath;
}
return encodedPath + '?' + encodedQuery;
}
}

View File

@@ -0,0 +1,256 @@
package okhttp3.internal.http;
import com.ubt.jimu.diy.model.DiyPreviewStep;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.HttpRetryException;
import java.net.ProtocolException;
import java.net.Proxy;
import java.net.SocketTimeoutException;
import java.security.cert.CertificateException;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSocketFactory;
import okhttp3.Address;
import okhttp3.Call;
import okhttp3.CertificatePinner;
import okhttp3.EventListener;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.Route;
import okhttp3.internal.Util;
import okhttp3.internal.connection.RouteException;
import okhttp3.internal.connection.StreamAllocation;
import okhttp3.internal.http2.ConnectionShutdownException;
/* loaded from: classes2.dex */
public final class RetryAndFollowUpInterceptor implements Interceptor {
private static final int MAX_FOLLOW_UPS = 20;
private Object callStackTrace;
private volatile boolean canceled;
private final OkHttpClient client;
private final boolean forWebSocket;
private volatile StreamAllocation streamAllocation;
public RetryAndFollowUpInterceptor(OkHttpClient okHttpClient, boolean z) {
this.client = okHttpClient;
this.forWebSocket = z;
}
private Address createAddress(HttpUrl httpUrl) {
SSLSocketFactory sSLSocketFactory;
HostnameVerifier hostnameVerifier;
CertificatePinner certificatePinner;
if (httpUrl.isHttps()) {
SSLSocketFactory sslSocketFactory = this.client.sslSocketFactory();
hostnameVerifier = this.client.hostnameVerifier();
sSLSocketFactory = sslSocketFactory;
certificatePinner = this.client.certificatePinner();
} else {
sSLSocketFactory = null;
hostnameVerifier = null;
certificatePinner = null;
}
return new Address(httpUrl.host(), httpUrl.port(), this.client.dns(), this.client.socketFactory(), sSLSocketFactory, hostnameVerifier, certificatePinner, this.client.proxyAuthenticator(), this.client.proxy(), this.client.protocols(), this.client.connectionSpecs(), this.client.proxySelector());
}
private Request followUpRequest(Response response, Route route) throws IOException {
String header;
HttpUrl resolve;
if (response == null) {
throw new IllegalStateException();
}
int code = response.code();
String method = response.request().method();
if (code == 307 || code == 308) {
if (!method.equals("GET") && !method.equals("HEAD")) {
return null;
}
} else {
if (code == 401) {
return this.client.authenticator().authenticate(route, response);
}
if (code == 503) {
if ((response.priorResponse() == null || response.priorResponse().code() != 503) && retryAfter(response, Integer.MAX_VALUE) == 0) {
return response.request();
}
return null;
}
if (code == 407) {
if ((route != null ? route.proxy() : this.client.proxy()).type() == Proxy.Type.HTTP) {
return this.client.proxyAuthenticator().authenticate(route, response);
}
throw new ProtocolException("Received HTTP_PROXY_AUTH (407) code while not using proxy");
}
if (code == 408) {
if (!this.client.retryOnConnectionFailure() || (response.request().body() instanceof UnrepeatableRequestBody)) {
return null;
}
if ((response.priorResponse() == null || response.priorResponse().code() != 408) && retryAfter(response, 0) <= 0) {
return response.request();
}
return null;
}
switch (code) {
case 300:
case DiyPreviewStep.TYPE_PROGRAM /* 301 */:
case 302:
case 303:
break;
default:
return null;
}
}
if (!this.client.followRedirects() || (header = response.header("Location")) == null || (resolve = response.request().url().resolve(header)) == null) {
return null;
}
if (!resolve.scheme().equals(response.request().url().scheme()) && !this.client.followSslRedirects()) {
return null;
}
Request.Builder newBuilder = response.request().newBuilder();
if (HttpMethod.permitsRequestBody(method)) {
boolean redirectsWithBody = HttpMethod.redirectsWithBody(method);
if (HttpMethod.redirectsToGet(method)) {
newBuilder.method("GET", null);
} else {
newBuilder.method(method, redirectsWithBody ? response.request().body() : null);
}
if (!redirectsWithBody) {
newBuilder.removeHeader("Transfer-Encoding");
newBuilder.removeHeader("Content-Length");
newBuilder.removeHeader("Content-Type");
}
}
if (!sameConnection(response, resolve)) {
newBuilder.removeHeader("Authorization");
}
return newBuilder.url(resolve).build();
}
private boolean isRecoverable(IOException iOException, boolean z) {
if (iOException instanceof ProtocolException) {
return false;
}
return iOException instanceof InterruptedIOException ? (iOException instanceof SocketTimeoutException) && !z : (((iOException instanceof SSLHandshakeException) && (iOException.getCause() instanceof CertificateException)) || (iOException instanceof SSLPeerUnverifiedException)) ? false : true;
}
private boolean recover(IOException iOException, StreamAllocation streamAllocation, boolean z, Request request) {
streamAllocation.streamFailed(iOException);
if (this.client.retryOnConnectionFailure()) {
return !(z && (request.body() instanceof UnrepeatableRequestBody)) && isRecoverable(iOException, z) && streamAllocation.hasMoreRoutes();
}
return false;
}
private int retryAfter(Response response, int i) {
String header = response.header("Retry-After");
if (header == null) {
return i;
}
if (header.matches("\\d+")) {
return Integer.valueOf(header).intValue();
}
return Integer.MAX_VALUE;
}
private boolean sameConnection(Response response, HttpUrl httpUrl) {
HttpUrl url = response.request().url();
return url.host().equals(httpUrl.host()) && url.port() == httpUrl.port() && url.scheme().equals(httpUrl.scheme());
}
public void cancel() {
this.canceled = true;
StreamAllocation streamAllocation = this.streamAllocation;
if (streamAllocation != null) {
streamAllocation.cancel();
}
}
@Override // okhttp3.Interceptor
public Response intercept(Interceptor.Chain chain) throws IOException {
Response proceed;
Request followUpRequest;
Request request = chain.request();
RealInterceptorChain realInterceptorChain = (RealInterceptorChain) chain;
Call call = realInterceptorChain.call();
EventListener eventListener = realInterceptorChain.eventListener();
StreamAllocation streamAllocation = new StreamAllocation(this.client.connectionPool(), createAddress(request.url()), call, eventListener, this.callStackTrace);
this.streamAllocation = streamAllocation;
Response response = null;
int i = 0;
while (!this.canceled) {
try {
try {
try {
proceed = realInterceptorChain.proceed(request, streamAllocation, null, null);
if (response != null) {
proceed = proceed.newBuilder().priorResponse(response.newBuilder().body(null).build()).build();
}
try {
followUpRequest = followUpRequest(proceed, streamAllocation.route());
} catch (IOException e) {
streamAllocation.release();
throw e;
}
} catch (RouteException e2) {
if (!recover(e2.getLastConnectException(), streamAllocation, false, request)) {
throw e2.getFirstConnectException();
}
}
} catch (IOException e3) {
if (!recover(e3, streamAllocation, !(e3 instanceof ConnectionShutdownException), request)) {
throw e3;
}
}
if (followUpRequest == null) {
if (!this.forWebSocket) {
streamAllocation.release();
}
return proceed;
}
Util.closeQuietly(proceed.body());
int i2 = i + 1;
if (i2 > 20) {
streamAllocation.release();
throw new ProtocolException("Too many follow-up requests: " + i2);
}
if (followUpRequest.body() instanceof UnrepeatableRequestBody) {
streamAllocation.release();
throw new HttpRetryException("Cannot retry streamed HTTP body", proceed.code());
}
if (!sameConnection(proceed, followUpRequest.url())) {
streamAllocation.release();
streamAllocation = new StreamAllocation(this.client.connectionPool(), createAddress(followUpRequest.url()), call, eventListener, this.callStackTrace);
this.streamAllocation = streamAllocation;
} else if (streamAllocation.codec() != null) {
throw new IllegalStateException("Closing the body of " + proceed + " didn't close its backing stream. Bad interceptor?");
}
response = proceed;
request = followUpRequest;
i = i2;
} catch (Throwable th) {
streamAllocation.streamFailed(null);
streamAllocation.release();
throw th;
}
}
streamAllocation.release();
throw new IOException("Canceled");
}
public boolean isCanceled() {
return this.canceled;
}
public void setCallStackTrace(Object obj) {
this.callStackTrace = obj;
}
public StreamAllocation streamAllocation() {
return this.streamAllocation;
}
}

View File

@@ -0,0 +1,82 @@
package okhttp3.internal.http;
import java.io.IOException;
import java.net.ProtocolException;
import okhttp3.Protocol;
import okhttp3.Response;
/* loaded from: classes2.dex */
public final class StatusLine {
public static final int HTTP_CONTINUE = 100;
public static final int HTTP_PERM_REDIRECT = 308;
public static final int HTTP_TEMP_REDIRECT = 307;
public final int code;
public final String message;
public final Protocol protocol;
public StatusLine(Protocol protocol, int i, String str) {
this.protocol = protocol;
this.code = i;
this.message = str;
}
public static StatusLine get(Response response) {
return new StatusLine(response.protocol(), response.code(), response.message());
}
public static StatusLine parse(String str) throws IOException {
Protocol protocol;
String str2;
int i = 9;
if (str.startsWith("HTTP/1.")) {
if (str.length() < 9 || str.charAt(8) != ' ') {
throw new ProtocolException("Unexpected status line: " + str);
}
int charAt = str.charAt(7) - '0';
if (charAt == 0) {
protocol = Protocol.HTTP_1_0;
} else {
if (charAt != 1) {
throw new ProtocolException("Unexpected status line: " + str);
}
protocol = Protocol.HTTP_1_1;
}
} else {
if (!str.startsWith("ICY ")) {
throw new ProtocolException("Unexpected status line: " + str);
}
protocol = Protocol.HTTP_1_0;
i = 4;
}
int i2 = i + 3;
if (str.length() < i2) {
throw new ProtocolException("Unexpected status line: " + str);
}
try {
int parseInt = Integer.parseInt(str.substring(i, i2));
if (str.length() <= i2) {
str2 = "";
} else {
if (str.charAt(i2) != ' ') {
throw new ProtocolException("Unexpected status line: " + str);
}
str2 = str.substring(i + 4);
}
return new StatusLine(protocol, parseInt, str2);
} catch (NumberFormatException unused) {
throw new ProtocolException("Unexpected status line: " + str);
}
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append(this.protocol == Protocol.HTTP_1_0 ? "HTTP/1.0" : "HTTP/1.1");
sb.append(' ');
sb.append(this.code);
if (this.message != null) {
sb.append(' ');
sb.append(this.message);
}
return sb.toString();
}
}

View File

@@ -0,0 +1,5 @@
package okhttp3.internal.http;
/* loaded from: classes2.dex */
public interface UnrepeatableRequestBody {
}