package okhttp3.internal.http;

import java.io.IOException;
import java.net.ProtocolException;
import kotlin.jvm.internal.o;
import n2.AbstractC2613d;
import okhttp3.EventListener;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.internal.connection.Exchange;
import okhttp3.internal.connection.RealCall;
import okhttp3.internal.connection.RealConnection;
import okhttp3.internal.http2.ConnectionShutdownException;
import p5.AbstractC2732b;
import p5.I;

/* JADX INFO: loaded from: classes3.dex */
public final class CallServerInterceptor implements Interceptor {
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:101:0x019f A[Catch: IOException -> 0x0109, TryCatch #0 {IOException -> 0x0109, blocks: (B:69:0x00f8, B:71:0x0101, B:74:0x010c, B:82:0x0130, B:84:0x0139, B:85:0x013f, B:86:0x0153, B:88:0x0175, B:97:0x0192, B:101:0x019f, B:103:0x01b0, B:105:0x01ba, B:106:0x01c4, B:90:0x017f), top: B:114:0x00f8 }] */
    /* JADX WARN: Removed duplicated region for block: B:113:0x01ce A[ADDED_TO_REGION, REMOVE] */
    /* JADX WARN: Removed duplicated region for block: B:64:0x00ee  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x00f7  */
    /* JADX WARN: Removed duplicated region for block: B:76:0x0125  */
    /* JADX WARN: Removed duplicated region for block: B:77:0x0127  */
    /* JADX WARN: Removed duplicated region for block: B:84:0x0139 A[Catch: IOException -> 0x0109, TryCatch #0 {IOException -> 0x0109, blocks: (B:69:0x00f8, B:71:0x0101, B:74:0x010c, B:82:0x0130, B:84:0x0139, B:85:0x013f, B:86:0x0153, B:88:0x0175, B:97:0x0192, B:101:0x019f, B:103:0x01b0, B:105:0x01ba, B:106:0x01c4, B:90:0x017f), top: B:114:0x00f8 }] */
    /* JADX WARN: Removed duplicated region for block: B:88:0x0175 A[Catch: IOException -> 0x0109, TryCatch #0 {IOException -> 0x0109, blocks: (B:69:0x00f8, B:71:0x0101, B:74:0x010c, B:82:0x0130, B:84:0x0139, B:85:0x013f, B:86:0x0153, B:88:0x0175, B:97:0x0192, B:101:0x019f, B:103:0x01b0, B:105:0x01ba, B:106:0x01c4, B:90:0x017f), top: B:114:0x00f8 }] */
    /* JADX WARN: Removed duplicated region for block: B:90:0x017f A[Catch: IOException -> 0x0109, TRY_LEAVE, TryCatch #0 {IOException -> 0x0109, blocks: (B:69:0x00f8, B:71:0x0101, B:74:0x010c, B:82:0x0130, B:84:0x0139, B:85:0x013f, B:86:0x0153, B:88:0x0175, B:97:0x0192, B:101:0x019f, B:103:0x01b0, B:105:0x01ba, B:106:0x01c4, B:90:0x017f), top: B:114:0x00f8 }] */
    /* JADX WARN: Removed duplicated region for block: B:93:0x018a  */
    /* JADX WARN: Removed duplicated region for block: B:95:0x018e  */
    /* JADX WARN: Removed duplicated region for block: B:97:0x0192 A[Catch: IOException -> 0x0109, TRY_ENTER, TryCatch #0 {IOException -> 0x0109, blocks: (B:69:0x00f8, B:71:0x0101, B:74:0x010c, B:82:0x0130, B:84:0x0139, B:85:0x013f, B:86:0x0153, B:88:0x0175, B:97:0x0192, B:101:0x019f, B:103:0x01b0, B:105:0x01ba, B:106:0x01c4, B:90:0x017f), top: B:114:0x00f8 }] */
    /* JADX WARN: Removed duplicated region for block: B:98:0x0197  */
    /* JADX WARN: Type inference failed for: r16v0 */
    /* JADX WARN: Type inference failed for: r16v1 */
    /* JADX WARN: Type inference failed for: r16v2 */
    /* JADX WARN: Type inference failed for: r16v3 */
    /* JADX WARN: Type inference failed for: r16v4 */
    /* JADX WARN: Type inference failed for: r18v10 */
    /* JADX WARN: Type inference failed for: r18v11 */
    /* JADX WARN: Type inference failed for: r18v12 */
    /* JADX WARN: Type inference failed for: r18v13 */
    /* JADX WARN: Type inference failed for: r18v14, types: [okhttp3.internal.http.ExchangeCodec] */
    /* JADX WARN: Type inference failed for: r18v15 */
    /* JADX WARN: Type inference failed for: r18v16 */
    /* JADX WARN: Type inference failed for: r18v17 */
    /* JADX WARN: Type inference failed for: r18v18 */
    /* JADX WARN: Type inference failed for: r18v19 */
    /* JADX WARN: Type inference failed for: r18v2 */
    /* JADX WARN: Type inference failed for: r18v20 */
    /* JADX WARN: Type inference failed for: r18v3, types: [okhttp3.internal.http.ExchangeCodec] */
    /* JADX WARN: Type inference failed for: r18v4 */
    /* JADX WARN: Type inference failed for: r18v5 */
    /* JADX WARN: Type inference failed for: r18v6, types: [okhttp3.internal.http.ExchangeCodec] */
    /* JADX WARN: Type inference failed for: r18v7 */
    /* JADX WARN: Type inference failed for: r18v8 */
    /* JADX WARN: Type inference failed for: r18v9 */
    /* JADX WARN: Type inference failed for: r6v3 */
    /* JADX WARN: Type inference failed for: r6v4 */
    /* JADX WARN: Type inference failed for: r6v5 */
    /* JADX WARN: Type inference failed for: r6v6 */
    /* JADX WARN: Type inference failed for: r6v8 */
    /* JADX WARN: Type inference failed for: r8v0, types: [okhttp3.internal.http.ExchangeCodec] */
    /* JADX WARN: Type inference failed for: r8v2 */
    /* JADX WARN: Type inference failed for: r8v5 */
    @Override // okhttp3.Interceptor
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Response a(RealInterceptorChain realInterceptorChain) throws Throwable {
        ?? r16;
        Response.Builder builderD;
        ?? r18;
        EventListener eventListener;
        IOException iOException;
        IOException iOException2;
        ?? r6;
        ?? r182;
        Response responseA;
        int i6;
        Response responseA2;
        ResponseBody responseBody;
        ?? r183;
        boolean z6;
        ?? r184;
        boolean z7;
        ?? r185;
        Exchange exchange = realInterceptorChain.f22387d;
        o.e(exchange);
        EventListener eventListener2 = exchange.f22291b;
        RealCall call = exchange.f22290a;
        ?? r8 = exchange.f22293d;
        RealConnection realConnection = exchange.f22295f;
        Request request = realInterceptorChain.f22388e;
        RequestBody requestBody = request.f22128d;
        long jCurrentTimeMillis = System.currentTimeMillis();
        try {
            try {
                eventListener2.getClass();
                o.h(call, "call");
                r8.b(request);
                try {
                } catch (IOException e6) {
                    e = e6;
                    eventListener = eventListener2;
                    r18 = r8;
                    r8 = 1;
                    iOException = null;
                    r16 = r8;
                    builderD = null;
                    if (e instanceof ConnectionShutdownException) {
                        throw e;
                    }
                    throw e;
                }
            } catch (IOException e7) {
                eventListener2.getClass();
                o.h(call, "call");
                exchange.e(e7);
                throw e7;
            }
        } catch (IOException e8) {
            e = e8;
        }
        try {
            if (HttpMethod.b(request.f22126b) && requestBody != null) {
                try {
                    if ("100-continue".equalsIgnoreCase(request.f22127c.g("Expect"))) {
                        try {
                            try {
                                r8.f();
                                builderD = exchange.d(true);
                                try {
                                    eventListener2.getClass();
                                    o.h(call, "call");
                                    z7 = false;
                                } catch (IOException e9) {
                                    e = e9;
                                    eventListener = eventListener2;
                                    r184 = r8;
                                    iOException = null;
                                    r16 = 1;
                                    r18 = r184;
                                    if (e instanceof ConnectionShutdownException) {
                                    }
                                }
                            } catch (IOException e10) {
                                eventListener2.getClass();
                                o.h(call, "call");
                                exchange.e(e10);
                                throw e10;
                            }
                        } catch (IOException e11) {
                            e = e11;
                            eventListener = eventListener2;
                            r184 = r8;
                            builderD = null;
                            iOException = null;
                            r16 = 1;
                            r18 = r184;
                            if (e instanceof ConnectionShutdownException) {
                            }
                        }
                    } else {
                        z7 = true;
                        builderD = null;
                    }
                    if (builderD == null) {
                        try {
                            I iB = AbstractC2732b.b(exchange.b(request));
                            requestBody.c(iB);
                            iB.close();
                            eventListener = eventListener2;
                            r185 = r8;
                            z6 = z7;
                            iOException = null;
                            r183 = r185;
                        } catch (IOException e12) {
                            e = e12;
                            eventListener = eventListener2;
                            r185 = r8;
                            r16 = z7;
                            iOException = null;
                            r18 = r185;
                            if (e instanceof ConnectionShutdownException) {
                            }
                        }
                    } else {
                        eventListener = eventListener2;
                        r185 = r8;
                        try {
                            call.h(exchange, true, false, null);
                            if (!(realConnection.f22342g != null)) {
                                r185.e().k();
                            }
                            z6 = z7;
                            iOException = null;
                            r183 = r185;
                        } catch (IOException e13) {
                            e = e13;
                            r16 = z7;
                            iOException = null;
                            r18 = r185;
                            if (e instanceof ConnectionShutdownException) {
                            }
                        }
                    }
                } catch (IOException e14) {
                    e = e14;
                }
                if (builderD == null) {
                    try {
                        builderD = exchange.d(false);
                        o.e(builderD);
                        if (r6 != 0) {
                            eventListener.getClass();
                            o.h(call, "call");
                            r6 = 0;
                        }
                    } catch (IOException e15) {
                        if (iOException2 == null) {
                            throw e15;
                        }
                        AbstractC2613d.b(iOException2, e15);
                        throw iOException2;
                    }
                }
                builderD.f22153a = request;
                builderD.f22157e = realConnection.f22340e;
                builderD.f22163k = jCurrentTimeMillis;
                builderD.l = System.currentTimeMillis();
                responseA = builderD.a();
                i6 = responseA.f22143d;
                if (i6 == 100 || (102 <= i6 && i6 < 200)) {
                    Response.Builder builderD2 = exchange.d(false);
                    o.e(builderD2);
                    if (r6 != 0) {
                        eventListener.getClass();
                        o.h(call, "call");
                    }
                    builderD2.f22153a = request;
                    builderD2.f22157e = realConnection.f22340e;
                    builderD2.f22163k = jCurrentTimeMillis;
                    builderD2.l = System.currentTimeMillis();
                    responseA = builderD2.a();
                    i6 = responseA.f22143d;
                }
                eventListener.getClass();
                o.h(call, "call");
                Response.Builder builderD3 = responseA.d();
                builderD3.f22159g = exchange.c(responseA);
                responseA2 = builderD3.a();
                if ("close".equalsIgnoreCase(responseA2.f22140a.f22127c.g("Connection")) || "close".equalsIgnoreCase(Response.b("Connection", responseA2))) {
                    r182.e().k();
                }
                if (i6 == 204 || i6 == 205) {
                    responseBody = responseA2.f22146j;
                    if ((responseBody == null ? responseBody.a() : -1L) > 0) {
                        StringBuilder sb = new StringBuilder("HTTP ");
                        sb.append(i6);
                        sb.append(" had non-zero Content-Length: ");
                        sb.append(responseBody != null ? Long.valueOf(responseBody.a()) : iOException);
                        throw new ProtocolException(sb.toString());
                    }
                }
                return responseA2;
            }
            eventListener = eventListener2;
            r183 = r8;
            z6 = true;
            iOException = null;
            call.h(exchange, true, false, null);
            builderD = null;
            r183.a();
            r6 = z6;
            iOException2 = iOException;
            r182 = r183;
            if (builderD == null) {
            }
            builderD.f22153a = request;
            builderD.f22157e = realConnection.f22340e;
            builderD.f22163k = jCurrentTimeMillis;
            builderD.l = System.currentTimeMillis();
            responseA = builderD.a();
            i6 = responseA.f22143d;
            if (i6 == 100) {
                Response.Builder builderD22 = exchange.d(false);
                o.e(builderD22);
                if (r6 != 0) {
                }
                builderD22.f22153a = request;
                builderD22.f22157e = realConnection.f22340e;
                builderD22.f22163k = jCurrentTimeMillis;
                builderD22.l = System.currentTimeMillis();
                responseA = builderD22.a();
                i6 = responseA.f22143d;
            }
            eventListener.getClass();
            o.h(call, "call");
            Response.Builder builderD32 = responseA.d();
            builderD32.f22159g = exchange.c(responseA);
            responseA2 = builderD32.a();
            if ("close".equalsIgnoreCase(responseA2.f22140a.f22127c.g("Connection"))) {
                r182.e().k();
            }
            if (i6 == 204) {
                responseBody = responseA2.f22146j;
                if ((responseBody == null ? responseBody.a() : -1L) > 0) {
                }
            }
            return responseA2;
        } catch (IOException e16) {
            try {
                exchange.e(e16);
                throw e16;
            } catch (IOException e17) {
                e = e17;
                r16 = z6;
                r18 = r183;
                if ((e instanceof ConnectionShutdownException) || !exchange.f22294e) {
                    throw e;
                }
                iOException2 = e;
                r6 = r16;
                r182 = r18;
                if (builderD == null) {
                }
                builderD.f22153a = request;
                builderD.f22157e = realConnection.f22340e;
                builderD.f22163k = jCurrentTimeMillis;
                builderD.l = System.currentTimeMillis();
                responseA = builderD.a();
                i6 = responseA.f22143d;
                if (i6 == 100) {
                }
                eventListener.getClass();
                o.h(call, "call");
                Response.Builder builderD322 = responseA.d();
                builderD322.f22159g = exchange.c(responseA);
                responseA2 = builderD322.a();
                if ("close".equalsIgnoreCase(responseA2.f22140a.f22127c.g("Connection"))) {
                }
                if (i6 == 204) {
                }
                return responseA2;
            }
        }
    }
}
