package e5;

import a.AbstractC0386a;
import com.google.android.gms.internal.measurement.C1;
import d5.AbstractC0844a;
import g6.o;
import java.io.IOException;
import java.net.ProtocolException;
import java.util.regex.Pattern;
import k7.A;
import k7.B;
import k7.C;
import k7.E;
import k7.l;
import k7.r;
import k7.s;
import k7.y;
import k7.z;
import n4.u0;
import r7.C1511a;
import x7.C1731g;
import x7.InterfaceC1733i;

/* JADX INFO: renamed from: e5.d, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public final class C0884d implements r {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final /* synthetic */ int f12476a;

    public /* synthetic */ C0884d(int i) {
        this.f12476a = i;
    }

    /* JADX WARN: Removed duplicated region for block: B:110:0x01c6 A[ADDED_TO_REGION, REMOVE] */
    /* JADX WARN: Removed duplicated region for block: B:60:0x00ed  */
    /* JADX WARN: Removed duplicated region for block: B:64:0x00f4  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x0105 A[PHI: r19
      0x0105: PHI (r19v3 k7.B) = (r19v2 k7.B), (r19v4 k7.B) binds: [B:63:0x00f2, B:66:0x00fc] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:73:0x0123  */
    /* JADX WARN: Removed duplicated region for block: B:81:0x0137 A[Catch: IOException -> 0x0108, TryCatch #11 {IOException -> 0x0108, blocks: (B:65:0x00f5, B:67:0x00fe, B:71:0x010b, B:79:0x012e, B:81:0x0137, B:82:0x013a, B:83:0x014e, B:85:0x016d, B:94:0x018a, B:98:0x0197, B:100:0x01a8, B:102:0x01b2, B:103:0x01bc, B:87:0x0177), top: B:214:0x00f5 }] */
    /* JADX WARN: Removed duplicated region for block: B:87:0x0177 A[Catch: IOException -> 0x0108, TRY_LEAVE, TryCatch #11 {IOException -> 0x0108, blocks: (B:65:0x00f5, B:67:0x00fe, B:71:0x010b, B:79:0x012e, B:81:0x0137, B:82:0x013a, B:83:0x014e, B:85:0x016d, B:94:0x018a, B:98:0x0197, B:100:0x01a8, B:102:0x01b2, B:103:0x01bc, B:87:0x0177), top: B:214:0x00f5 }] */
    /* JADX WARN: Removed duplicated region for block: B:92:0x0186  */
    /* JADX WARN: Removed duplicated region for block: B:94:0x018a A[Catch: IOException -> 0x0108, TRY_ENTER, TryCatch #11 {IOException -> 0x0108, blocks: (B:65:0x00f5, B:67:0x00fe, B:71:0x010b, B:79:0x012e, B:81:0x0137, B:82:0x013a, B:83:0x014e, B:85:0x016d, B:94:0x018a, B:98:0x0197, B:100:0x01a8, B:102:0x01b2, B:103:0x01bc, B:87:0x0177), top: B:214:0x00f5 }] */
    /* JADX WARN: Removed duplicated region for block: B:95:0x018f  */
    /* JADX WARN: Removed duplicated region for block: B:98:0x0197 A[Catch: IOException -> 0x0108, TryCatch #11 {IOException -> 0x0108, blocks: (B:65:0x00f5, B:67:0x00fe, B:71:0x010b, B:79:0x012e, B:81:0x0137, B:82:0x013a, B:83:0x014e, B:85:0x016d, B:94:0x018a, B:98:0x0197, B:100:0x01a8, B:102:0x01b2, B:103:0x01bc, B:87:0x0177), top: B:214:0x00f5 }] */
    @Override // k7.r
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final C a(p7.d dVar) throws Throwable {
        A a3;
        s sVarB;
        boolean z8;
        B bC;
        IOException iOException;
        B b8;
        C cA;
        int i;
        C cA2;
        E e8;
        IOException iOException2;
        B bC2;
        boolean z9;
        boolean z10;
        switch (this.f12476a) {
            case u0.f15495q /* 0 */:
                y yVar = dVar.f16161e;
                if (P6.g.a(yVar.f14203b, "GET") || (a3 = yVar.f14205d) == null) {
                    return dVar.b(yVar);
                }
                try {
                    C1731g c1731g = new C1731g();
                    try {
                        a3.c(c1731g);
                        byte[] bArrD = o.f12958a.d(c1731g.V(c1731g.f18765r));
                        K2.e eVarB = yVar.b();
                        Pattern pattern = s.f14130d;
                        s sVarM = AbstractC0386a.m("application/octet-stream");
                        String str = yVar.f14203b;
                        int iHashCode = str.hashCode();
                        if (iHashCode != 79599) {
                            if (iHashCode != 2461856) {
                                if (iHashCode == 2012838315 && str.equals("DELETE")) {
                                    int length = bArrD.length;
                                    P6.g.e(bArrD, "<this>");
                                    l7.b.c(bArrD.length, 0, length);
                                    eVarB.J("DELETE", new z(sVarM, length, bArrD));
                                }
                            } else if (str.equals("POST")) {
                                int length2 = bArrD.length;
                                P6.g.e(bArrD, "<this>");
                                l7.b.c(bArrD.length, 0, length2);
                                eVarB.J("POST", new z(sVarM, length2, bArrD));
                            }
                        } else if (str.equals("PUT")) {
                            int length3 = bArrD.length;
                            P6.g.e(bArrD, "<this>");
                            l7.b.c(bArrD.length, 0, length3);
                            eVarB.J("PUT", new z(sVarM, length3, bArrD));
                        }
                        return dVar.b(eVarB.q());
                    } finally {
                    }
                } catch (IOException e9) {
                    throw e9;
                } catch (Exception e10) {
                    throw new W4.d(e10.getMessage());
                }
            case 1:
                y yVar2 = dVar.f16161e;
                if (!P6.g.a(yVar2.f14204c.a("IncludeOptional"), "true")) {
                    return dVar.b(yVar2);
                }
                K2.e eVarB2 = yVar2.b();
                eVarB2.K("IncludeOptional");
                C cB = dVar.b(eVarB2.q());
                E e11 = cB.f14016w;
                String str2 = (e11 == null || (sVarB = e11.b()) == null) ? null : sVarB.f14132a;
                if (!cB.b() || !P6.g.a(str2, "application/octet-stream")) {
                    return cB;
                }
                long jA = e11.a();
                if (jA > 2147483647L) {
                    throw new IOException(AbstractC0844a.i(jA, "Cannot buffer entire body for content length: "));
                }
                InterfaceC1733i interfaceC1733iG = e11.g();
                try {
                    byte[] bArrU = interfaceC1733iG.U();
                    interfaceC1733iG.close();
                    int length4 = bArrU.length;
                    if (jA != -1 && jA != length4) {
                        throw new IOException("Content-Length (" + jA + ") and stream length (" + length4 + ") disagree");
                    }
                    if (bArrU.length == 0) {
                        return cB;
                    }
                    try {
                        byte[] bArrB = o.f12958a.b(bArrU);
                        B bG = cB.g();
                        P6.g.e(bArrB, "<this>");
                        bG.f14001g = l.c(new String(bArrB, X6.a.f7235a));
                        return bG.a();
                    } catch (IOException e12) {
                        cB.close();
                        throw e12;
                    } catch (Exception e13) {
                        cB.close();
                        throw new W4.d(e13.getMessage());
                    }
                } catch (Throwable th) {
                    try {
                        throw th;
                    } catch (Throwable th2) {
                        C1.g(interfaceC1733iG, th);
                        throw th2;
                    }
                }
            default:
                o7.d dVar2 = dVar.f16160d;
                P6.g.b(dVar2);
                o7.i iVar = dVar2.f15947a;
                p7.b bVar = dVar2.f15949c;
                o7.l lVar = dVar2.f15951e;
                y yVar3 = dVar.f16161e;
                A a8 = yVar3.f14205d;
                long jCurrentTimeMillis = System.currentTimeMillis();
                try {
                    try {
                        P6.g.e(iVar, "call");
                        bVar.b(yVar3);
                        break;
                    } catch (IOException e14) {
                        e = e14;
                    }
                    try {
                        if (!W3.b.r(yVar3.f14203b) || a8 == null) {
                            iOException2 = null;
                            iVar.k(dVar2, true, false, null);
                            z8 = true;
                            bC = null;
                        } else {
                            try {
                                if ("100-continue".equalsIgnoreCase(yVar3.f14204c.a("Expect"))) {
                                    try {
                                        bVar.f();
                                        bC2 = dVar2.c(true);
                                        try {
                                            P6.g.e(iVar, "call");
                                            z9 = false;
                                        } catch (IOException e15) {
                                            e = e15;
                                            bC = bC2;
                                            z8 = true;
                                            if (!(e instanceof C1511a) || !dVar2.f15950d) {
                                                throw e;
                                            }
                                            iOException = e;
                                            if (bC != null) {
                                            }
                                            b8.f13995a = yVar3;
                                            b8.f13999e = lVar.f15986e;
                                            b8.f14004k = jCurrentTimeMillis;
                                            b8.f14005l = System.currentTimeMillis();
                                            cA = b8.a();
                                            i = cA.f14013t;
                                            if (i != 100) {
                                                B bC3 = dVar2.c(false);
                                                P6.g.b(bC3);
                                                if (z8) {
                                                }
                                                bC3.f13995a = yVar3;
                                                bC3.f13999e = lVar.f15986e;
                                                bC3.f14004k = jCurrentTimeMillis;
                                                bC3.f14005l = System.currentTimeMillis();
                                                cA = bC3.a();
                                                i = cA.f14013t;
                                            }
                                            P6.g.e(iVar, "call");
                                            B bG2 = cA.g();
                                            bG2.f14001g = dVar2.b(cA);
                                            cA2 = bG2.a();
                                            if (!"close".equalsIgnoreCase(cA2.f14010q.f14204c.a("Connection"))) {
                                                bVar.h().l();
                                            }
                                            if (i != 204) {
                                                e8 = cA2.f14016w;
                                                if ((e8 == null ? e8.a() : -1L) > 0) {
                                                }
                                            }
                                            return cA2;
                                        }
                                    } catch (IOException e16) {
                                        P6.g.e(iVar, "call");
                                        dVar2.d(e16);
                                        throw e16;
                                    }
                                } else {
                                    z9 = true;
                                    bC2 = null;
                                }
                                try {
                                    if (bC2 == null) {
                                        try {
                                            A a9 = yVar3.f14205d;
                                            P6.g.b(a9);
                                            z10 = z9;
                                            bC = bC2;
                                            long jA2 = a9.a();
                                            P6.g.e(iVar, "call");
                                            x7.A aB = s7.l.b(new o7.b(dVar2, bVar.c(yVar3, jA2), jA2));
                                            a8.c(aB);
                                            aB.close();
                                        } catch (IOException e17) {
                                            e = e17;
                                            z10 = z9;
                                            bC = bC2;
                                            z8 = z10;
                                            if (!(e instanceof C1511a)) {
                                            }
                                        }
                                    } else {
                                        z10 = z9;
                                        bC = bC2;
                                        iVar.k(dVar2, true, false, null);
                                        if (!(lVar.f15988g != null)) {
                                            bVar.h().l();
                                        }
                                    }
                                    z8 = z10;
                                    iOException2 = null;
                                } catch (IOException e18) {
                                    e = e18;
                                }
                            } catch (IOException e19) {
                                e = e19;
                                z8 = true;
                                bC = null;
                            }
                        }
                        try {
                            bVar.e();
                            iOException = iOException2;
                        } catch (IOException e20) {
                            try {
                                dVar2.d(e20);
                                throw e20;
                            } catch (IOException e21) {
                                e = e21;
                                if (!(e instanceof C1511a)) {
                                    throw e;
                                }
                                throw e;
                            }
                        }
                        break;
                    } catch (IOException e22) {
                        e = e22;
                        z8 = true;
                        bC = null;
                        if (!(e instanceof C1511a)) {
                        }
                    }
                    if (bC != null) {
                        try {
                            bC = dVar2.c(false);
                            P6.g.b(bC);
                            if (z8) {
                                P6.g.e(iVar, "call");
                                b8 = bC;
                                z8 = false;
                            } else {
                                b8 = bC;
                            }
                        } catch (IOException e23) {
                            if (iOException == null) {
                                throw e23;
                            }
                            android.support.v4.media.session.a.a(iOException, e23);
                            throw iOException;
                        }
                    }
                    b8.f13995a = yVar3;
                    b8.f13999e = lVar.f15986e;
                    b8.f14004k = jCurrentTimeMillis;
                    b8.f14005l = System.currentTimeMillis();
                    cA = b8.a();
                    i = cA.f14013t;
                    if (i != 100 || (102 <= i && i < 200)) {
                        B bC32 = dVar2.c(false);
                        P6.g.b(bC32);
                        if (z8) {
                            P6.g.e(iVar, "call");
                        }
                        bC32.f13995a = yVar3;
                        bC32.f13999e = lVar.f15986e;
                        bC32.f14004k = jCurrentTimeMillis;
                        bC32.f14005l = System.currentTimeMillis();
                        cA = bC32.a();
                        i = cA.f14013t;
                    }
                    P6.g.e(iVar, "call");
                    B bG22 = cA.g();
                    bG22.f14001g = dVar2.b(cA);
                    cA2 = bG22.a();
                    if (!"close".equalsIgnoreCase(cA2.f14010q.f14204c.a("Connection")) || "close".equalsIgnoreCase(C.a("Connection", cA2))) {
                        bVar.h().l();
                    }
                    if (i != 204 || i == 205) {
                        e8 = cA2.f14016w;
                        if ((e8 == null ? e8.a() : -1L) > 0) {
                            StringBuilder sb = new StringBuilder("HTTP ");
                            sb.append(i);
                            sb.append(" had non-zero Content-Length: ");
                            sb.append(e8 != null ? Long.valueOf(e8.a()) : null);
                            throw new ProtocolException(sb.toString());
                        }
                    }
                    return cA2;
                } catch (IOException e24) {
                    P6.g.e(iVar, "call");
                    dVar2.d(e24);
                    throw e24;
                }
        }
    }
}
