package 㿎.ሽ.㴹;

import com.appsflyer.share.Constants;
import com.facebook.GraphRequest;
import com.google.zxing.datamatrix.encoder.ErrorCorrection;
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.HostnameVerifier;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSocketFactory;
import okhttp3.internal.connection.RouteException;
import okhttp3.internal.http2.ConnectionShutdownException;
import ඓ.ⁱ.K.ඓ.C1252;
import ඓ.K.K.K.C1293;
import 㿎.AbstractC2533;
import 㿎.AbstractC2537;
import 㿎.AbstractC2636;
import 㿎.AbstractC2651;
import 㿎.AbstractC2661;
import 㿎.C2531;
import 㿎.C2539;
import 㿎.C2625;
import 㿎.C2638;
import 㿎.C2640;
import 㿎.C2644;
import 㿎.C2671;
import 㿎.ሽ.C2540;
import 㿎.ሽ.ඓ.C2544;
import 㿎.ሽ.ඓ.C2548;

/* renamed from: 㿎.ሽ.㴹.㿎  reason: contains not printable characters */
/* compiled from: RetryAndFollowUpInterceptor */
public final class C2586 implements AbstractC2661 {

    /* renamed from: ʬ  reason: contains not printable characters */
    public volatile C2548 f8704;

    /* renamed from: ඓ  reason: contains not printable characters */
    public volatile boolean f8705;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final boolean f8706;

    /* renamed from: K  reason: contains not printable characters */
    public final C2625 f8707;

    /* renamed from: 㸾  reason: contains not printable characters */
    public Object f8708;

    public C2586(C2625 r1, boolean z) {
        this.f8707 = r1;
        this.f8706 = z;
    }

    /* renamed from: K  reason: contains not printable characters */
    public final boolean m6796(C2671 r3, C2531 r4) {
        C2531 r32 = r3.f9087.f8985;
        return r32.f8542.equals(r4.f8542) && r32.f8536 == r4.f8536 && r32.f8540.equals(r4.f8540);
    }

    /* renamed from: K  reason: contains not printable characters */
    public final C2644 m6793(C2671 r7, C2539 r8) throws IOException {
        Proxy proxy;
        if (r7 != null) {
            int i = r7.f9092;
            C2644 r1 = r7.f9087;
            String str = r1.f8984;
            AbstractC2651 r5 = null;
            if (i == 307 || i == 308) {
                if (!str.equals("GET") && !str.equals("HEAD")) {
                    return null;
                }
            } else if (i == 401) {
                ((AbstractC2636.C2637) this.f8707.f8879).m6946(r8, r7);
                return null;
            } else if (i == 503) {
                C2671 r82 = r7.f9085;
                if ((r82 == null || r82.f9092 != 503) && m6791(r7, Integer.MAX_VALUE) == 0) {
                    return r7.f9087;
                }
                return null;
            } else if (i == 407) {
                if (r8 != null) {
                    proxy = r8.f8558;
                } else {
                    proxy = this.f8707.f8875;
                }
                if (proxy.type() == Proxy.Type.HTTP) {
                    ((AbstractC2636.C2637) this.f8707.f8892).m6946(r8, r7);
                    return null;
                }
                throw new ProtocolException("Received HTTP_PROXY_AUTH (407) code while not using proxy");
            } else if (i != 408) {
                switch (i) {
                    case 300:
                    case ErrorCorrection.MODULO_VALUE:
                    case 302:
                    case 303:
                        break;
                    default:
                        return null;
                }
            } else if (!this.f8707.f8895) {
                return null;
            } else {
                AbstractC2651 r0 = r1.f8987;
                C2671 r02 = r7.f9085;
                if ((r02 == null || r02.f9092 != 408) && m6791(r7, 0) <= 0) {
                    return r7.f9087;
                }
                return null;
            }
            if (!this.f8707.f8882) {
                return null;
            }
            String r83 = r7.f9088.m6996(Constants.HTTP_REDIRECT_URL_HEADER_FIELD);
            if (r83 == null) {
                r83 = null;
            }
            if (r83 == null) {
                return null;
            }
            C2531.C2532 r84 = r7.f9087.f8985.m6598(r83);
            C2531 r85 = r84 != null ? r84.m6607() : null;
            if (r85 == null) {
                return null;
            }
            if (!r85.f8540.equals(r7.f9087.f8985.f8540) && !this.f8707.f8897) {
                return null;
            }
            C2644.C2645 r03 = r7.f9087.m6961();
            if (C1252.m3330(str)) {
                boolean equals = str.equals("PROPFIND");
                if (!str.equals("PROPFIND")) {
                    r03.m6967("GET", (AbstractC2651) null);
                } else {
                    if (equals) {
                        r5 = r7.f9087.f8987;
                    }
                    r03.m6967(str, r5);
                }
                if (!equals) {
                    r03.f8988.m6999("Transfer-Encoding");
                    r03.f8988.m6999("Content-Length");
                    r03.f8988.m6999(GraphRequest.CONTENT_TYPE_HEADER);
                }
            }
            if (!m6796(r7, r85)) {
                r03.f8988.m6999("Authorization");
            }
            r03.m6968(r85);
            return r03.m6970();
        }
        throw new IllegalStateException();
    }

    @Override // 㿎.AbstractC2661
    /* renamed from: K  reason: contains not printable characters */
    public C2671 m6794(AbstractC2661.AbstractC2662 k) throws IOException {
        C2583 r15 = (C2583) k;
        C2644 r0 = r15.f8698;
        AbstractC2537 r7 = r15.f8694;
        AbstractC2533 r8 = r15.f8700;
        C2548 r9 = new C2548(this.f8707.f8900, m6792(r0.f8985), r7, r8, this.f8708);
        this.f8704 = r9;
        C2671 r1 = null;
        int i = 0;
        while (!this.f8705) {
            try {
                C2671 r02 = r15.m6790(r0, r9, null, null);
                if (r1 != null) {
                    C2671.C2672 r03 = r02.m7007();
                    C2671.C2672 k2 = new C2671.C2672(r1);
                    k2.f9100 = null;
                    C2671 r12 = k2.m7010();
                    if (r12.f9093 == null) {
                        r03.f9103 = r12;
                        r02 = r03.m7010();
                    } else {
                        throw new IllegalArgumentException("priorResponse.body != null");
                    }
                }
                try {
                    C2644 r122 = m6793(r02, r9.f8608);
                    if (r122 == null) {
                        if (!this.f8706) {
                            r9.m6677();
                        }
                        return r02;
                    }
                    C2540.m6651(r02.f9093);
                    int i2 = i + 1;
                    if (i2 <= 20) {
                        AbstractC2651 r13 = r122.f8987;
                        if (!m6796(r02, r122.f8985)) {
                            r9.m6677();
                            r9 = new C2548(this.f8707.f8900, m6792(r122.f8985), r7, r8, this.f8708);
                            this.f8704 = r9;
                        } else if (r9.m6678() != null) {
                            throw new IllegalStateException("Closing the body of " + r02 + " didn't close its backing stream. Bad interceptor?");
                        }
                        r1 = r02;
                        r0 = r122;
                        i = i2;
                    } else {
                        r9.m6677();
                        throw new ProtocolException(C1293.m3408("Too many follow-up requests: ", i2));
                    }
                } catch (IOException e) {
                    r9.m6677();
                    throw e;
                }
            } catch (RouteException e2) {
                if (!m6795(e2.getLastConnectException(), r9, false, r0)) {
                    throw e2.getFirstConnectException();
                }
            } catch (IOException e3) {
                if (!m6795(e3, r9, !(e3 instanceof ConnectionShutdownException), r0)) {
                    throw e3;
                }
            } catch (Throwable th) {
                r9.m6684(null);
                r9.m6677();
                throw th;
            }
        }
        r9.m6677();
        throw new IOException("Canceled");
    }

    /* renamed from: K  reason: contains not printable characters */
    public final int m6791(C2671 r2, int i) {
        String r22 = r2.f9088.m6996("Retry-After");
        if (r22 == null) {
            r22 = null;
        }
        if (r22 == null) {
            return i;
        }
        if (r22.matches("\\d+")) {
            return Integer.valueOf(r22).intValue();
        }
        return Integer.MAX_VALUE;
    }

    /* renamed from: K  reason: contains not printable characters */
    public final boolean m6795(IOException iOException, C2548 r4, boolean z, C2644 r6) {
        C2544.C2545 k;
        r4.m6684(iOException);
        if (!this.f8707.f8895) {
            return false;
        }
        if (z) {
            AbstractC2651 r62 = r6.f8987;
        }
        if (!(!(iOException instanceof ProtocolException) && (!(iOException instanceof InterruptedIOException) ? (!(iOException instanceof SSLHandshakeException) || !(iOException.getCause() instanceof CertificateException)) && !(iOException instanceof SSLPeerUnverifiedException) : (iOException instanceof SocketTimeoutException) && !z))) {
            return false;
        }
        if (!(r4.f8608 != null || ((k = r4.f8613) != null && k.m6672()) || r4.f8620.m6671())) {
            return false;
        }
        return true;
    }

    /* renamed from: K  reason: contains not printable characters */
    public final C2640 m6792(C2531 r19) {
        C2638 r12;
        HostnameVerifier hostnameVerifier;
        SSLSocketFactory sSLSocketFactory;
        if (r19.f8540.equals("https")) {
            C2625 r2 = this.f8707;
            SSLSocketFactory sSLSocketFactory2 = r2.f8876;
            HostnameVerifier hostnameVerifier2 = r2.f8878;
            r12 = r2.f8883;
            sSLSocketFactory = sSLSocketFactory2;
            hostnameVerifier = hostnameVerifier2;
        } else {
            sSLSocketFactory = null;
            hostnameVerifier = null;
            r12 = null;
        }
        String str = r19.f8542;
        int i = r19.f8536;
        C2625 r1 = this.f8707;
        return new C2640(str, i, r1.f8877, r1.f8901, sSLSocketFactory, hostnameVerifier, r12, r1.f8892, r1.f8875, r1.f8898, r1.f8880, r1.f8885);
    }
}
