what-the-bank/sources/okhttp3/internal/http/RetryAndFollowUpInterceptor...

368 lines
16 KiB
Java
Raw Normal View History

2024-07-27 18:17:47 +07:00
package okhttp3.internal.http;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.ProtocolException;
import java.net.Proxy;
import java.net.SocketTimeoutException;
import java.security.cert.CertificateException;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLPeerUnverifiedException;
import o.C14953gcr;
import o.C14957gcv;
import o.gdW;
import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.Route;
import okhttp3.internal.Util;
import okhttp3.internal.connection.Exchange;
import okhttp3.internal.connection.RealCall;
import okhttp3.internal.connection.RealConnection;
/* loaded from: classes.dex */
public final class RetryAndFollowUpInterceptor implements Interceptor {
public static final Companion Companion = new Companion(null);
private static final int MAX_FOLLOW_UPS = 20;
private final OkHttpClient client;
public RetryAndFollowUpInterceptor(OkHttpClient okHttpClient) {
C14957gcv.e(okHttpClient, "");
this.client = okHttpClient;
}
/* JADX WARN: Code restructure failed: missing block: B:11:0x0026, code lost:
if (r5 == null) goto L10;
*/
/* JADX WARN: Code restructure failed: missing block: B:12:0x0028, code lost:
r0 = r0.newBuilder().priorResponse(r5.newBuilder().body(null).build()).build();
*/
/* JADX WARN: Code restructure failed: missing block: B:13:0x0040, code lost:
r5 = r0;
r0 = r1.getInterceptorScopedExchange$okhttp();
r8 = followUpRequest(r5, r0);
*/
/* JADX WARN: Code restructure failed: missing block: B:14:0x0049, code lost:
if (r8 != null) goto L18;
*/
/* JADX WARN: Code restructure failed: missing block: B:15:0x005a, code lost:
r0 = r8.body();
*/
/* JADX WARN: Code restructure failed: missing block: B:16:0x005e, code lost:
if (r0 == null) goto L24;
*/
/* JADX WARN: Code restructure failed: missing block: B:18:0x0064, code lost:
if (r0.isOneShot() == false) goto L24;
*/
/* JADX WARN: Code restructure failed: missing block: B:20:0x0066, code lost:
r1.exitNetworkInterceptorExchange$okhttp(false);
*/
/* JADX WARN: Code restructure failed: missing block: B:21:0x0069, code lost:
return r5;
*/
/* JADX WARN: Code restructure failed: missing block: B:23:0x006a, code lost:
r0 = r5.body();
*/
/* JADX WARN: Code restructure failed: missing block: B:24:0x006e, code lost:
if (r0 == null) goto L27;
*/
/* JADX WARN: Code restructure failed: missing block: B:25:0x0070, code lost:
okhttp3.internal.Util.closeQuietly(r0);
*/
/* JADX WARN: Code restructure failed: missing block: B:26:0x0075, code lost:
r6 = r6 + 1;
*/
/* JADX WARN: Code restructure failed: missing block: B:27:0x0078, code lost:
if (r6 > 20) goto L58;
*/
/* JADX WARN: Code restructure failed: missing block: B:31:0x008e, code lost:
throw new java.net.ProtocolException(o.C14957gcv.c("Too many follow-up requests: ", java.lang.Integer.valueOf(r6)));
*/
/* JADX WARN: Code restructure failed: missing block: B:33:0x004b, code lost:
if (r0 == null) goto L16;
*/
/* JADX WARN: Code restructure failed: missing block: B:35:0x0051, code lost:
if (r0.isDuplex$okhttp() == false) goto L16;
*/
/* JADX WARN: Code restructure failed: missing block: B:36:0x0053, code lost:
r1.timeoutEarlyExit();
*/
/* JADX WARN: Code restructure failed: missing block: B:37:0x0056, code lost:
r1.exitNetworkInterceptorExchange$okhttp(false);
*/
/* JADX WARN: Code restructure failed: missing block: B:38:0x0059, code lost:
return r5;
*/
@Override // okhttp3.Interceptor
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public final okhttp3.Response intercept(okhttp3.Interceptor.Chain r11) throws java.io.IOException {
/*
r10 = this;
java.lang.String r0 = ""
o.C14957gcv.e(r11, r0)
okhttp3.internal.http.RealInterceptorChain r11 = (okhttp3.internal.http.RealInterceptorChain) r11
okhttp3.Request r0 = r11.getRequest$okhttp()
okhttp3.internal.connection.RealCall r1 = r11.getCall$okhttp()
o.gaI r2 = o.C14851gaI.c
java.util.List r2 = (java.util.List) r2
r3 = 0
r4 = 0
r6 = r3
r5 = r4
L17:
r7 = 1
r8 = r7
L19:
r1.enterNetworkInterceptorExchange(r0, r8)
boolean r8 = r1.isCanceled() // Catch: java.lang.Throwable -> Ld5
if (r8 != 0) goto Lcd
okhttp3.Response r0 = r11.proceed(r0) // Catch: java.io.IOException -> L8f okhttp3.internal.connection.RouteException -> La7 java.lang.Throwable -> Ld5
if (r5 == 0) goto L40
okhttp3.Response$Builder r0 = r0.newBuilder() // Catch: java.lang.Throwable -> Ld5
okhttp3.Response$Builder r5 = r5.newBuilder() // Catch: java.lang.Throwable -> Ld5
okhttp3.Response$Builder r5 = r5.body(r4) // Catch: java.lang.Throwable -> Ld5
okhttp3.Response r5 = r5.build() // Catch: java.lang.Throwable -> Ld5
okhttp3.Response$Builder r0 = r0.priorResponse(r5) // Catch: java.lang.Throwable -> Ld5
okhttp3.Response r0 = r0.build() // Catch: java.lang.Throwable -> Ld5
L40:
r5 = r0
okhttp3.internal.connection.Exchange r0 = r1.getInterceptorScopedExchange$okhttp() // Catch: java.lang.Throwable -> Ld5
okhttp3.Request r8 = r10.followUpRequest(r5, r0) // Catch: java.lang.Throwable -> Ld5
if (r8 != 0) goto L5a
if (r0 == 0) goto L56
boolean r11 = r0.isDuplex$okhttp() // Catch: java.lang.Throwable -> Ld5
if (r11 == 0) goto L56
r1.timeoutEarlyExit() // Catch: java.lang.Throwable -> Ld5
L56:
r1.exitNetworkInterceptorExchange$okhttp(r3)
return r5
L5a:
okhttp3.RequestBody r0 = r8.body() // Catch: java.lang.Throwable -> Ld5
if (r0 == 0) goto L6a
boolean r0 = r0.isOneShot() // Catch: java.lang.Throwable -> Ld5
if (r0 == 0) goto L6a
r1.exitNetworkInterceptorExchange$okhttp(r3)
return r5
L6a:
okhttp3.ResponseBody r0 = r5.body() // Catch: java.lang.Throwable -> Ld5
if (r0 == 0) goto L75
java.io.Closeable r0 = (java.io.Closeable) r0 // Catch: java.lang.Throwable -> Ld5
okhttp3.internal.Util.closeQuietly(r0) // Catch: java.lang.Throwable -> Ld5
L75:
int r6 = r6 + r7
r0 = 20
if (r6 > r0) goto L7f
r1.exitNetworkInterceptorExchange$okhttp(r7)
r0 = r8
goto L17
L7f:
java.net.ProtocolException r11 = new java.net.ProtocolException // Catch: java.lang.Throwable -> Ld5
java.lang.String r0 = "Too many follow-up requests: "
java.lang.Integer r2 = java.lang.Integer.valueOf(r6) // Catch: java.lang.Throwable -> Ld5
java.lang.String r0 = o.C14957gcv.c(r0, r2) // Catch: java.lang.Throwable -> Ld5
r11.<init>(r0) // Catch: java.lang.Throwable -> Ld5
throw r11 // Catch: java.lang.Throwable -> Ld5
L8f:
r8 = move-exception
boolean r9 = r8 instanceof okhttp3.internal.http2.ConnectionShutdownException // Catch: java.lang.Throwable -> Ld5
r9 = r9 ^ r7
boolean r9 = r10.recover(r8, r1, r0, r9) // Catch: java.lang.Throwable -> Ld5
if (r9 == 0) goto La0
java.util.Collection r2 = (java.util.Collection) r2 // Catch: java.lang.Throwable -> Ld5
java.util.List r2 = o.C14881gav.a(r2, r8) // Catch: java.lang.Throwable -> Ld5
goto Lbc
La0:
java.lang.Exception r8 = (java.lang.Exception) r8 // Catch: java.lang.Throwable -> Ld5
java.lang.Throwable r11 = okhttp3.internal.Util.withSuppressed(r8, r2) // Catch: java.lang.Throwable -> Ld5
throw r11 // Catch: java.lang.Throwable -> Ld5
La7:
r8 = move-exception
java.io.IOException r9 = r8.getLastConnectException() // Catch: java.lang.Throwable -> Ld5
boolean r9 = r10.recover(r9, r1, r0, r3) // Catch: java.lang.Throwable -> Ld5
if (r9 == 0) goto Lc2
java.util.Collection r2 = (java.util.Collection) r2 // Catch: java.lang.Throwable -> Ld5
java.io.IOException r8 = r8.getFirstConnectException() // Catch: java.lang.Throwable -> Ld5
java.util.List r2 = o.C14881gav.a(r2, r8) // Catch: java.lang.Throwable -> Ld5
Lbc:
r1.exitNetworkInterceptorExchange$okhttp(r7)
r8 = r3
goto L19
Lc2:
java.io.IOException r11 = r8.getFirstConnectException() // Catch: java.lang.Throwable -> Ld5
java.lang.Exception r11 = (java.lang.Exception) r11 // Catch: java.lang.Throwable -> Ld5
java.lang.Throwable r11 = okhttp3.internal.Util.withSuppressed(r11, r2) // Catch: java.lang.Throwable -> Ld5
throw r11 // Catch: java.lang.Throwable -> Ld5
Lcd:
java.io.IOException r11 = new java.io.IOException // Catch: java.lang.Throwable -> Ld5
java.lang.String r0 = "Canceled"
r11.<init>(r0) // Catch: java.lang.Throwable -> Ld5
throw r11 // Catch: java.lang.Throwable -> Ld5
Ld5:
r11 = move-exception
r1.exitNetworkInterceptorExchange$okhttp(r7)
throw r11
*/
throw new UnsupportedOperationException("Method not decompiled: okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(okhttp3.Interceptor$Chain):okhttp3.Response");
}
private final boolean recover(IOException iOException, RealCall realCall, Request request, boolean z) {
if (this.client.retryOnConnectionFailure()) {
return !(z && requestIsOneShot(iOException, request)) && isRecoverable(iOException, z) && realCall.retryAfterFailure();
}
return false;
}
private final boolean requestIsOneShot(IOException iOException, Request request) {
RequestBody body = request.body();
return (body != null && body.isOneShot()) || (iOException instanceof FileNotFoundException);
}
private final 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 final Request followUpRequest(Response response, Exchange exchange) throws IOException {
RealConnection connection$okhttp;
Route route = (exchange == null || (connection$okhttp = exchange.getConnection$okhttp()) == null) ? null : connection$okhttp.route();
int code = response.code();
String method = response.request().method();
if (code != 307 && code != 308) {
if (code == 401) {
return this.client.authenticator().authenticate(route, response);
}
if (code == 421) {
RequestBody body = response.request().body();
if ((body != null && body.isOneShot()) || exchange == null || !exchange.isCoalescedConnection$okhttp()) {
return null;
}
exchange.getConnection$okhttp().noCoalescedConnections$okhttp();
return response.request();
}
if (code == 503) {
Response priorResponse = response.priorResponse();
if ((priorResponse == null || priorResponse.code() != 503) && retryAfter(response, Integer.MAX_VALUE) == 0) {
return response.request();
}
return null;
}
if (code == 407) {
C14957gcv.e(route);
if (route.proxy().type() != Proxy.Type.HTTP) {
throw new ProtocolException("Received HTTP_PROXY_AUTH (407) code while not using proxy");
}
return this.client.proxyAuthenticator().authenticate(route, response);
}
if (code == 408) {
if (!this.client.retryOnConnectionFailure()) {
return null;
}
RequestBody body2 = response.request().body();
if (body2 != null && body2.isOneShot()) {
return null;
}
Response priorResponse2 = response.priorResponse();
if ((priorResponse2 == null || priorResponse2.code() != 408) && retryAfter(response, 0) <= 0) {
return response.request();
}
return null;
}
switch (code) {
case 300:
case 301:
case 302:
case 303:
break;
default:
return null;
}
}
return buildRedirectRequest(response, method);
}
private final Request buildRedirectRequest(Response response, String str) {
String header$default;
HttpUrl resolve;
if (!this.client.followRedirects() || (header$default = Response.header$default(response, com.google.common.net.HttpHeaders.LOCATION, null, 2, null)) == null || (resolve = response.request().url().resolve(header$default)) == null) {
return null;
}
if (!C14957gcv.b((Object) resolve.scheme(), (Object) response.request().url().scheme()) && !this.client.followSslRedirects()) {
return null;
}
Request.Builder newBuilder = response.request().newBuilder();
if (HttpMethod.permitsRequestBody(str)) {
int code = response.code();
boolean z = HttpMethod.INSTANCE.redirectsWithBody(str) || code == 308 || code == 307;
if (HttpMethod.INSTANCE.redirectsToGet(str) && code != 308 && code != 307) {
newBuilder.method("GET", null);
} else {
newBuilder.method(str, z ? response.request().body() : null);
}
if (!z) {
newBuilder.removeHeader(com.google.common.net.HttpHeaders.TRANSFER_ENCODING);
newBuilder.removeHeader(com.google.common.net.HttpHeaders.CONTENT_LENGTH);
newBuilder.removeHeader(com.google.common.net.HttpHeaders.CONTENT_TYPE);
}
}
if (!Util.canReuseConnectionFor(response.request().url(), resolve)) {
newBuilder.removeHeader(com.google.common.net.HttpHeaders.AUTHORIZATION);
}
return newBuilder.url(resolve).build();
}
private final int retryAfter(Response response, int i) {
String header$default = Response.header$default(response, com.google.common.net.HttpHeaders.RETRY_AFTER, null, 2, null);
if (header$default == null) {
return i;
}
String str = header$default;
gdW gdw = new gdW("\\d+");
C14957gcv.e(str, "");
if (!gdw.e.matcher(str).matches()) {
return Integer.MAX_VALUE;
}
Integer valueOf = Integer.valueOf(header$default);
C14957gcv.c(valueOf, "");
return valueOf.intValue();
}
/* loaded from: classes.dex */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(C14953gcr c14953gcr) {
this();
}
}
}