package 㿎.ሽ.㿎;

import com.facebook.GraphRequest;
import java.io.IOException;
import java.net.ProtocolException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import okhttp3.Protocol;
import okhttp3.internal.http2.ErrorCode;
import okio.ByteString;
import ඓ.ⁱ.K.ඓ.C1252;
import ᨨ.AbstractC1473;
import ᨨ.AbstractC1490;
import ᨨ.AbstractC1494;
import ᨨ.C1486;
import ᨨ.C1492;
import 㿎.AbstractC2533;
import 㿎.AbstractC2537;
import 㿎.AbstractC2632;
import 㿎.AbstractC2661;
import 㿎.C2625;
import 㿎.C2644;
import 㿎.C2667;
import 㿎.C2671;
import 㿎.ሽ.AbstractC2570;
import 㿎.ሽ.C2540;
import 㿎.ሽ.ඓ.C2548;
import 㿎.ሽ.㴹.AbstractC2576;
import 㿎.ሽ.㴹.C2577;
import 㿎.ሽ.㴹.C2578;
import 㿎.ሽ.㴹.C2581;
import 㿎.ሽ.㴹.C2583;

/* renamed from: 㿎.ሽ.㿎.㸾  reason: contains not printable characters */
/* compiled from: Http2Codec */
public final class C2619 implements AbstractC2576 {

    /* renamed from: Ԕ  reason: contains not printable characters */
    public static final List<ByteString> f8833 = C2540.m6647(f8840, f8836, f8841, f8835, f8834, f8839, f8837, f8842, C2614.f8816, C2614.f8815, C2614.f8818, C2614.f8814);

    /* renamed from: ᕣ  reason: contains not printable characters */
    public static final ByteString f8834 = ByteString.encodeUtf8("te");

    /* renamed from: ᨨ  reason: contains not printable characters */
    public static final ByteString f8835 = ByteString.encodeUtf8("proxy-connection");

    /* renamed from: ⁱ  reason: contains not printable characters */
    public static final ByteString f8836 = ByteString.encodeUtf8("host");

    /* renamed from: 㑃  reason: contains not printable characters */
    public static final ByteString f8837 = ByteString.encodeUtf8("encoding");

    /* renamed from: 㗗  reason: contains not printable characters */
    public static final List<ByteString> f8838 = C2540.m6647(f8840, f8836, f8841, f8835, f8834, f8839, f8837, f8842);

    /* renamed from: 㳳  reason: contains not printable characters */
    public static final ByteString f8839 = ByteString.encodeUtf8("transfer-encoding");

    /* renamed from: 㴹  reason: contains not printable characters */
    public static final ByteString f8840 = ByteString.encodeUtf8("connection");

    /* renamed from: 㿎  reason: contains not printable characters */
    public static final ByteString f8841 = ByteString.encodeUtf8("keep-alive");

    /* renamed from: 䁗  reason: contains not printable characters */
    public static final ByteString f8842 = ByteString.encodeUtf8("upgrade");

    /* renamed from: ʬ  reason: contains not printable characters */
    public final C2591 f8843;

    /* renamed from: ඓ  reason: contains not printable characters */
    public final Protocol f8844;

    /* renamed from: ῲ  reason: contains not printable characters */
    public final C2548 f8845;

    /* renamed from: K  reason: contains not printable characters */
    public final AbstractC2661.AbstractC2662 f8846;

    /* renamed from: 㸾  reason: contains not printable characters */
    public C2621 f8847;

    /* renamed from: 㿎.ሽ.㿎.㸾$K  reason: contains not printable characters */
    /* compiled from: Http2Codec */
    public class C2620 extends AbstractC1490 {

        /* renamed from: ʬ  reason: contains not printable characters */
        public long f8848 = 0;

        /* renamed from: ῲ  reason: contains not printable characters */
        public boolean f8849 = false;

        public C2620(AbstractC1494 r2) {
            super(r2);
        }

        @Override // ᨨ.AbstractC1494, java.io.Closeable, java.lang.AutoCloseable, ᨨ.AbstractC1490
        public void close() throws IOException {
            super.close();
            m6897(null);
        }

        @Override // ᨨ.AbstractC1494, ᨨ.AbstractC1490
        public long read(C1492 r3, long j) throws IOException {
            try {
                long read = delegate().read(r3, j);
                if (read > 0) {
                    this.f8848 += read;
                }
                return read;
            } catch (IOException e) {
                m6897(e);
                throw e;
            }
        }

        /* renamed from: K  reason: contains not printable characters */
        public final void m6897(IOException iOException) {
            if (!this.f8849) {
                this.f8849 = true;
                C2619 r3 = C2619.this;
                r3.f8845.m6686(false, r3, this.f8848, iOException);
            }
        }
    }

    public C2619(C2625 r1, AbstractC2661.AbstractC2662 k, C2548 r3, C2591 r4) {
        Protocol protocol;
        this.f8846 = k;
        this.f8845 = r3;
        this.f8843 = r4;
        if (r1.f8898.contains(Protocol.H2_PRIOR_KNOWLEDGE)) {
            protocol = Protocol.H2_PRIOR_KNOWLEDGE;
        } else {
            protocol = Protocol.HTTP_2;
        }
        this.f8844 = protocol;
    }

    @Override // 㿎.ሽ.㴹.AbstractC2576
    public void cancel() {
        C2621 r0 = this.f8847;
        if (r0 != null) {
            r0.m6899(ErrorCode.CANCEL);
        }
    }

    @Override // 㿎.ሽ.㴹.AbstractC2576
    /* renamed from: ῲ  reason: contains not printable characters */
    public void m6891() throws IOException {
        this.f8843.f8720.flush();
    }

    @Override // 㿎.ሽ.㴹.AbstractC2576
    /* renamed from: K  reason: contains not printable characters */
    public AbstractC1473 m6892(C2644 r1, long j) {
        return this.f8847.m6898();
    }

    @Override // 㿎.ሽ.㴹.AbstractC2576
    /* renamed from: K  reason: contains not printable characters */
    public void m6896(C2644 r9) throws IOException {
        if (this.f8847 == null) {
            boolean z = r9.f8987 != null;
            C2667 r2 = r9.f8982;
            ArrayList arrayList = new ArrayList(r2.m6993() + 4);
            arrayList.add(new C2614(C2614.f8816, r9.f8984));
            arrayList.add(new C2614(C2614.f8815, C1252.m3342(r9.f8985)));
            String r4 = r9.f8982.m6996("Host");
            if (r4 != null) {
                arrayList.add(new C2614(C2614.f8814, r4));
            }
            arrayList.add(new C2614(C2614.f8818, r9.f8985.f8540));
            int r92 = r2.m6993();
            for (int i = 0; i < r92; i++) {
                ByteString encodeUtf8 = ByteString.encodeUtf8(r2.m6995(i).toLowerCase(Locale.US));
                if (!f8833.contains(encodeUtf8)) {
                    arrayList.add(new C2614(encodeUtf8, r2.m6994(i)));
                }
            }
            this.f8847 = this.f8843.m6813(0, arrayList, z);
            this.f8847.f8854.m3705((long) ((C2583) this.f8846).f8697, TimeUnit.MILLISECONDS);
            this.f8847.f8858.m3705((long) ((C2583) this.f8846).f8691, TimeUnit.MILLISECONDS);
        }
    }

    @Override // 㿎.ሽ.㴹.AbstractC2576
    /* renamed from: K  reason: contains not printable characters */
    public void m6895() throws IOException {
        this.f8847.m6898().close();
    }

    @Override // 㿎.ሽ.㴹.AbstractC2576
    /* renamed from: K  reason: contains not printable characters */
    public C2671.C2672 m6894(boolean z) throws IOException {
        List<C2614> r0 = this.f8847.m6903();
        Protocol protocol = this.f8844;
        C2667.C2668 k = new C2667.C2668();
        int size = r0.size();
        C2667.C2668 k2 = k;
        C2578 r2 = null;
        for (int i = 0; i < size; i++) {
            C2614 k3 = r0.get(i);
            if (k3 != null) {
                ByteString byteString = k3.f8821;
                String utf8 = k3.f8820.utf8();
                if (byteString.equals(C2614.f8813)) {
                    r2 = C2578.m6785("HTTP/1.1 " + utf8);
                } else if (!f8838.contains(byteString)) {
                    AbstractC2570.f8676.m6763(k2, byteString.utf8(), utf8);
                }
            } else if (r2 != null && r2.f8681 == 100) {
                k2 = new C2667.C2668();
                r2 = null;
            }
        }
        if (r2 != null) {
            C2671.C2672 k4 = new C2671.C2672();
            k4.f9099 = protocol;
            k4.f9095 = r2.f8681;
            k4.f9105 = r2.f8680;
            List<String> list = k2.f9081;
            C2667.C2668 k5 = new C2667.C2668();
            Collections.addAll(k5.f9081, (String[]) list.toArray(new String[list.size()]));
            k4.f9104 = k5;
            if (!z || AbstractC2570.f8676.m6757(k4) != 100) {
                return k4;
            }
            return null;
        }
        throw new ProtocolException("Expected ':status' header not present");
    }

    @Override // 㿎.ሽ.㴹.AbstractC2576
    /* renamed from: K  reason: contains not printable characters */
    public AbstractC2632 m6893(C2671 r5) throws IOException {
        C2548 r0 = this.f8845;
        AbstractC2533 r1 = r0.f8618;
        AbstractC2537 r02 = r0.f8610;
        r1.m6610();
        String r03 = r5.f9088.m6996(GraphRequest.CONTENT_TYPE_HEADER);
        if (r03 == null) {
            r03 = null;
        }
        return new C2581(r03, C2577.m6783(r5), C1486.m3741(new C2620(this.f8847.f8856)));
    }
}
