package okhttp3.internal.http;

import java.util.ArrayList;
import kotlin.jvm.internal.o;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.internal.connection.Exchange;
import okhttp3.internal.connection.RealCall;

/* JADX INFO: loaded from: classes3.dex */
public final class RealInterceptorChain implements Interceptor.Chain {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final RealCall f22384a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ArrayList f22385b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final int f22386c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final Exchange f22387d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final Request f22388e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final int f22389f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final int f22390g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final int f22391h;

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public int f22392i;

    public RealInterceptorChain(RealCall call, ArrayList arrayList, int i6, Exchange exchange, Request request, int i7, int i8, int i9) {
        o.h(call, "call");
        o.h(request, "request");
        this.f22384a = call;
        this.f22385b = arrayList;
        this.f22386c = i6;
        this.f22387d = exchange;
        this.f22388e = request;
        this.f22389f = i7;
        this.f22390g = i8;
        this.f22391h = i9;
    }

    public static RealInterceptorChain a(RealInterceptorChain realInterceptorChain, int i6, Exchange exchange, Request request, int i7) {
        if ((i7 & 1) != 0) {
            i6 = realInterceptorChain.f22386c;
        }
        int i8 = i6;
        if ((i7 & 2) != 0) {
            exchange = realInterceptorChain.f22387d;
        }
        Exchange exchange2 = exchange;
        if ((i7 & 4) != 0) {
            request = realInterceptorChain.f22388e;
        }
        Request request2 = request;
        o.h(request2, "request");
        return new RealInterceptorChain(realInterceptorChain.f22384a, realInterceptorChain.f22385b, i8, exchange2, request2, realInterceptorChain.f22389f, realInterceptorChain.f22390g, realInterceptorChain.f22391h);
    }

    public final Response b(Request request) {
        o.h(request, "request");
        ArrayList arrayList = this.f22385b;
        int size = arrayList.size();
        int i6 = this.f22386c;
        if (i6 >= size) {
            throw new IllegalStateException("Check failed.");
        }
        this.f22392i++;
        Exchange exchange = this.f22387d;
        if (exchange != null) {
            if (!exchange.f22292c.b(request.f22125a)) {
                throw new IllegalStateException(("network interceptor " + arrayList.get(i6 - 1) + " must retain the same host and port").toString());
            }
            if (this.f22392i != 1) {
                throw new IllegalStateException(("network interceptor " + arrayList.get(i6 - 1) + " must call proceed() exactly once").toString());
            }
        }
        int i7 = i6 + 1;
        RealInterceptorChain realInterceptorChainA = a(this, i7, null, request, 58);
        Interceptor interceptor = (Interceptor) arrayList.get(i6);
        Response responseA = interceptor.a(realInterceptorChainA);
        if (responseA == null) {
            throw new NullPointerException("interceptor " + interceptor + " returned null");
        }
        if (exchange != null && i7 < arrayList.size() && realInterceptorChainA.f22392i != 1) {
            throw new IllegalStateException(("network interceptor " + interceptor + " must call proceed() exactly once").toString());
        }
        if (responseA.f22146j != null) {
            return responseA;
        }
        throw new IllegalStateException(("interceptor " + interceptor + " returned a response with no body").toString());
    }
}
