package p447.p448.p453;

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 java.util.List;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLHandshakeException;
import javax.net.ssl.SSLPeerUnverifiedException;
import javax.net.ssl.SSLSocketFactory;
import kotlin.jvm.internal.DefaultConstructorMarker;
import okhttp3.internal.connection.RouteException;
import okhttp3.internal.http2.ConnectionShutdownException;
import p402.InterfaceC6540;
import p402.p403.C6560;
import p402.p403.C6563;
import p402.p411.p413.C6635;
import p402.p420.C6695;
import p447.AbstractC6930;
import p447.AbstractC6936;
import p447.C6860;
import p447.C6871;
import p447.C6908;
import p447.C6921;
import p447.C6926;
import p447.C6933;
import p447.C6938;
import p447.InterfaceC6912;
import p447.p448.C6943;
import p447.p448.p452.C6960;
import p447.p448.p452.C6963;
import p447.p448.p452.C6964;
import p447.p448.p452.C6968;
import p447.p448.p452.C6973;

/* JADX INFO: renamed from: ސ.ޣ.ޅ.ކ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6540
public final class C6989 implements InterfaceC6912 {

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C6921 f20342;

    /* JADX INFO: renamed from: ސ.ޣ.ޅ.ކ$֏, reason: contains not printable characters */
    public static final class C6990 {
        public C6990() {
        }

        public /* synthetic */ C6990(DefaultConstructorMarker defaultConstructorMarker) {
        }
    }

    static {
        new C6990(null);
    }

    public C6989(C6921 c6921) {
        if (c6921 != null) {
            this.f20342 = c6921;
        } else {
            C6635.m9824("client");
            throw null;
        }
    }

    @Override // p447.InterfaceC6912
    public C6933 intercept(InterfaceC6912.InterfaceC6913 interfaceC6913) throws Throwable {
        int i;
        List list;
        Object obj;
        boolean z;
        boolean z2;
        SSLSocketFactory sSLSocketFactory;
        HostnameVerifier hostnameVerifier;
        C6871 c6871;
        if (interfaceC6913 == null) {
            C6635.m9824("chain");
            throw null;
        }
        C6987 c6987 = (C6987) interfaceC6913;
        C6926 c6926 = c6987.f20335;
        C6964 c6964 = c6987.f20331;
        C6933 c6933 = null;
        int i2 = 0;
        C6926 c6926M10268 = c6926;
        List list2 = C6563.f19343;
        while (true) {
            List listM9780 = list2;
            boolean z3 = true;
            while (c6926M10268 != null) {
                if (!(c6964.f20274 == null)) {
                    throw new IllegalStateException("Check failed.".toString());
                }
                if (!(c6964.f20267 == null)) {
                    throw new IllegalStateException("cannot make a new request because the previous response is still open: please call response.close()".toString());
                }
                if (z3) {
                    C6973 c6973 = c6964.f20261;
                    C6908 c6908 = c6926M10268.f20128;
                    if (c6908.f20013) {
                        C6921 c6921 = c6964.f20275;
                        SSLSocketFactory sSLSocketFactory2 = c6921.f20074;
                        if (sSLSocketFactory2 == null) {
                            throw new IllegalStateException("CLEARTEXT-only client");
                        }
                        hostnameVerifier = c6921.f20078;
                        c6871 = c6921.f20079;
                        sSLSocketFactory = sSLSocketFactory2;
                    } else {
                        sSLSocketFactory = null;
                        hostnameVerifier = null;
                        c6871 = null;
                    }
                    String str = c6908.f20017;
                    int i3 = c6908.f20018;
                    C6921 c69212 = c6964.f20275;
                    list = listM9780;
                    i = i2;
                    obj = "Check failed.";
                    c6964.f20265 = new C6963(c6973, new C6860(str, i3, c69212.f20069, c69212.f20073, sSLSocketFactory, hostnameVerifier, c6871, c69212.f20072, c69212.f20070, c69212.f20077, c69212.f20076, c69212.f20071), c6964, c6964.f20262);
                } else {
                    i = i2;
                    list = listM9780;
                    obj = "Check failed.";
                }
                try {
                    if (c6964.mo10027()) {
                        throw new IOException("Canceled");
                    }
                    try {
                        try {
                            C6933 c6933Mo10101 = c6987.mo10101(c6926M10268);
                            if (c6933 != null) {
                                if (c6933Mo10101 == null) {
                                    throw null;
                                }
                                try {
                                    C6933.C6934 c6934 = new C6933.C6934(c6933Mo10101);
                                    C6933.C6934 c69342 = new C6933.C6934(c6933);
                                    c69342.f20165 = null;
                                    C6933 c6933M10133 = c69342.m10133();
                                    if (!(c6933M10133.f20152 == null)) {
                                        throw new IllegalArgumentException("priorResponse.body != null".toString());
                                    }
                                    c6934.f20168 = c6933M10133;
                                    c6933Mo10101 = c6934.m10133();
                                } catch (Throwable th) {
                                    th = th;
                                    z = true;
                                    c6964.m10220(z);
                                    throw th;
                                }
                            }
                            c6933 = c6933Mo10101;
                            C6960 c6960 = c6964.f20274;
                            try {
                                c6926M10268 = m10268(c6933, c6960);
                                if (c6926M10268 == null) {
                                    if (c6960 != null && c6960.f20233) {
                                        if (!(!c6964.f20271)) {
                                            throw new IllegalStateException(obj.toString());
                                        }
                                        c6964.f20271 = true;
                                        c6964.f20263.m10400();
                                    }
                                    c6964.m10220(false);
                                    return c6933;
                                }
                                AbstractC6936 abstractC6936 = c6933.f20152;
                                if (abstractC6936 != null) {
                                    C6943.m10164(abstractC6936);
                                }
                                i2 = i + 1;
                                if (i2 > 20) {
                                    throw new ProtocolException("Too many follow-up requests: " + i2);
                                }
                                c6964.m10220(true);
                                list2 = list;
                            } catch (Throwable th2) {
                                th = th2;
                                z = true;
                                c6964.m10220(z);
                                throw th;
                            }
                        } catch (IOException e) {
                            if (!m10269(e, c6964, c6926M10268, !(e instanceof ConnectionShutdownException))) {
                                C6943.m10158(e, (List<? extends Exception>) list);
                                throw e;
                            }
                            listM9780 = C6560.m9780(list, e);
                            z2 = true;
                            c6964.m10220(z2);
                            i2 = i;
                            z3 = false;
                        }
                    } catch (RouteException e2) {
                        List list3 = list;
                        if (!m10269(e2.f2193, c6964, c6926M10268, false)) {
                            IOException iOException = e2.f2194;
                            C6943.m10158(iOException, (List<? extends Exception>) list3);
                            throw iOException;
                        }
                        listM9780 = C6560.m9780(list3, e2.f2194);
                        z2 = true;
                        c6964.m10220(z2);
                        i2 = i;
                        z3 = false;
                    }
                } catch (Throwable th3) {
                    th = th3;
                }
            }
            C6635.m9824("request");
            throw null;
        }
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final int m10267(C6933 c6933, int i) {
        String strM10126 = C6933.m10126(c6933, "Retry-After", null, 2);
        if (strM10126 == null) {
            return i;
        }
        if (!new C6695("\\d+").m9854(strM10126)) {
            return Integer.MAX_VALUE;
        }
        Integer numValueOf = Integer.valueOf(strM10126);
        C6635.m9823((Object) numValueOf, "Integer.valueOf(header)");
        return numValueOf.intValue();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final C6926 m10268(C6933 c6933, C6960 c6960) throws ProtocolException {
        String strM10126;
        C6908 c6908M10082;
        C6968 c6968;
        C6938 c6938 = (c6960 == null || (c6968 = c6960.f20234) == null) ? null : c6968.f20299;
        int i = c6933.f20149;
        String str = c6933.f20146.f20129;
        if (i != 307 && i != 308) {
            if (i == 401) {
                return this.f20342.f20064.mo2523(c6938, c6933);
            }
            if (i == 421) {
                if (c6960 == null || !(!C6635.m9825((Object) c6960.f20237.f20258.f19900.f20017, (Object) c6960.f20234.f20299.f20176.f19900.f20017))) {
                    return null;
                }
                c6960.f20234.m10236();
                return c6933.f20146;
            }
            if (i == 503) {
                C6933 c69332 = c6933.f20155;
                if ((c69332 == null || c69332.f20149 != 503) && m10267(c6933, Integer.MAX_VALUE) == 0) {
                    return c6933.f20146;
                }
                return null;
            }
            if (i == 407) {
                if (c6938 == null) {
                    C6635.m9822();
                    throw null;
                }
                if (c6938.f20177.type() == Proxy.Type.HTTP) {
                    return this.f20342.f20072.mo2523(c6938, c6933);
                }
                throw new ProtocolException("Received HTTP_PROXY_AUTH (407) code while not using proxy");
            }
            if (i == 408) {
                if (!this.f20342.f20063) {
                    return null;
                }
                C6933 c69333 = c6933.f20155;
                if ((c69333 == null || c69333.f20149 != 408) && m10267(c6933, 0) <= 0) {
                    return c6933.f20146;
                }
                return null;
            }
            switch (i) {
                case 300:
                case 301:
                case 302:
                case 303:
                    break;
                default:
                    return null;
            }
        }
        if (!this.f20342.f20065 || (strM10126 = C6933.m10126(c6933, "Location", null, 2)) == null || (c6908M10082 = c6933.f20146.f20128.m10082(strM10126)) == null) {
            return null;
        }
        if (!C6635.m9825((Object) c6908M10082.f20014, (Object) c6933.f20146.f20128.f20014) && !this.f20342.f20066) {
            return null;
        }
        C6926 c6926 = c6933.f20146;
        if (c6926 == null) {
            throw null;
        }
        C6926.C6927 c6927 = new C6926.C6927(c6926);
        if (C6986.m10264(str)) {
            int i2 = c6933.f20149;
            boolean z = C6635.m9825((Object) str, (Object) "PROPFIND") || i2 == 308 || i2 == 307;
            if (!(true ^ C6635.m9825((Object) str, (Object) "PROPFIND")) || i2 == 308 || i2 == 307) {
                c6927.m10120(str, z ? c6933.f20146.f20131 : null);
            } else {
                c6927.m10120("GET", (AbstractC6930) null);
            }
            if (!z) {
                c6927.m10118("Transfer-Encoding");
                c6927.m10118("Content-Length");
                c6927.m10118("Content-Type");
            }
        }
        if (!C6943.m10169(c6933.f20146.f20128, c6908M10082)) {
            c6927.m10118("Authorization");
        }
        c6927.f20133 = c6908M10082;
        return c6927.m10123();
    }

    /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
    public final boolean m10269(IOException iOException, C6964 c6964, C6926 c6926, boolean z) {
        if (!this.f20342.f20063) {
            return false;
        }
        if (z) {
            AbstractC6930 abstractC6930 = c6926.f20131;
            if (iOException instanceof FileNotFoundException) {
                return false;
            }
        }
        if (!(!(iOException instanceof ProtocolException) && (!(iOException instanceof InterruptedIOException) ? ((iOException instanceof SSLHandshakeException) && (iOException.getCause() instanceof CertificateException)) || (iOException instanceof SSLPeerUnverifiedException) : !((iOException instanceof SocketTimeoutException) && !z)))) {
            return false;
        }
        C6963 c6963 = c6964.f20265;
        if (c6963 != null) {
            return c6963.m10213();
        }
        C6635.m9822();
        throw null;
    }
}
