package xq;

import com.amplifyframework.storage.ObjectMetadata;
import kotlin.jvm.internal.k;
import kotlin.jvm.internal.t;
import kotlin.text.y;
import uq.a0;
import uq.b0;
import uq.c;
import uq.d0;
import uq.e;
import uq.r;
import uq.u;
import uq.w;
import vq.l;
import vq.m;
import xq.b;
import zq.h;

/* loaded from: classes3.dex */
public final class a implements w {

    /* renamed from: a, reason: collision with root package name */
    public static final C1023a f51018a = new C1023a(null);

    /* renamed from: xq.a$a, reason: collision with other inner class name */
    /* loaded from: classes3.dex */
    public static final class C1023a {
        private C1023a() {
        }

        public /* synthetic */ C1023a(k kVar) {
            this();
        }

        /* JADX INFO: Access modifiers changed from: private */
        public final u b(u uVar, u uVar2) {
            int i10;
            boolean z10;
            boolean P;
            u.a aVar = new u.a();
            int size = uVar.size();
            for (0; i10 < size; i10 + 1) {
                String i11 = uVar.i(i10);
                String C = uVar.C(i10);
                z10 = y.z("Warning", i11, true);
                if (z10) {
                    P = y.P(C, "1", false, 2, null);
                    i10 = P ? i10 + 1 : 0;
                }
                if (c(i11) || !d(i11) || uVar2.e(i11) == null) {
                    aVar.d(i11, C);
                }
            }
            int size2 = uVar2.size();
            for (int i12 = 0; i12 < size2; i12++) {
                String i13 = uVar2.i(i12);
                if (!c(i13) && d(i13)) {
                    aVar.d(i13, uVar2.C(i12));
                }
            }
            return aVar.e();
        }

        private final boolean c(String str) {
            boolean z10;
            boolean z11;
            boolean z12;
            z10 = y.z("Content-Length", str, true);
            if (z10) {
                return true;
            }
            z11 = y.z(ObjectMetadata.CONTENT_ENCODING, str, true);
            if (z11) {
                return true;
            }
            z12 = y.z(ObjectMetadata.CONTENT_TYPE, str, true);
            return z12;
        }

        private final boolean d(String str) {
            boolean z10;
            boolean z11;
            boolean z12;
            boolean z13;
            boolean z14;
            boolean z15;
            boolean z16;
            boolean z17;
            z10 = y.z("Connection", str, true);
            if (!z10) {
                z11 = y.z("Keep-Alive", str, true);
                if (!z11) {
                    z12 = y.z("Proxy-Authenticate", str, true);
                    if (!z12) {
                        z13 = y.z("Proxy-Authorization", str, true);
                        if (!z13) {
                            z14 = y.z("TE", str, true);
                            if (!z14) {
                                z15 = y.z("Trailers", str, true);
                                if (!z15) {
                                    z16 = y.z("Transfer-Encoding", str, true);
                                    if (!z16) {
                                        z17 = y.z("Upgrade", str, true);
                                        if (!z17) {
                                            return true;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return false;
        }
    }

    public a(c cVar) {
    }

    @Override // uq.w
    public d0 intercept(w.a chain) {
        r rVar;
        t.g(chain, "chain");
        e call = chain.call();
        b b10 = new b.C1024b(System.currentTimeMillis(), chain.g(), null).b();
        b0 b11 = b10.b();
        d0 a10 = b10.a();
        h hVar = call instanceof h ? (h) call : null;
        if (hVar == null || (rVar = hVar.o()) == null) {
            rVar = r.NONE;
        }
        if (b11 == null && a10 == null) {
            d0 c10 = new d0.a().q(chain.g()).o(a0.HTTP_1_1).e(504).l("Unsatisfiable Request (only-if-cached)").r(-1L).p(System.currentTimeMillis()).c();
            rVar.satisfactionFailure(call, c10);
            return c10;
        }
        if (b11 == null) {
            t.d(a10);
            d0 c11 = a10.w().d(l.u(a10)).c();
            rVar.cacheHit(call, c11);
            return c11;
        }
        if (a10 != null) {
            rVar.cacheConditionalHit(call, a10);
        }
        d0 b12 = chain.b(b11);
        if (a10 != null) {
            boolean z10 = false;
            if (b12 != null && b12.f() == 304) {
                z10 = true;
            }
            if (z10) {
                a10.w().j(f51018a.b(a10.r(), b12.r())).r(b12.G()).p(b12.A()).d(l.u(a10)).m(l.u(b12)).c();
                b12.b().close();
                t.d(null);
                throw null;
            }
            m.f(a10.b());
        }
        t.d(b12);
        return b12.w().d(a10 != null ? l.u(a10) : null).m(l.u(b12)).c();
    }
}
