package 㿎.ሽ.㴹;

import com.facebook.GraphRequest;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import ᨨ.C1485;
import ᨨ.C1488;
import 㿎.AbstractC2651;
import 㿎.AbstractC2661;
import 㿎.AbstractC2669;
import 㿎.C2628;
import 㿎.C2644;
import 㿎.C2646;
import 㿎.C2667;
import 㿎.C2671;
import 㿎.ሽ.C2540;

/* renamed from: 㿎.ሽ.㴹.K  reason: contains not printable characters */
/* compiled from: BridgeInterceptor */
public final class C2582 implements AbstractC2661 {

    /* renamed from: K  reason: contains not printable characters */
    public final AbstractC2669 f8688;

    public C2582(AbstractC2669 r1) {
        this.f8688 = r1;
    }

    @Override // 㿎.AbstractC2661
    /* renamed from: K  reason: contains not printable characters */
    public C2671 m6788(AbstractC2661.AbstractC2662 k) throws IOException {
        boolean z;
        C2583 r15 = (C2583) k;
        C2644 r0 = r15.f8698;
        C2644.C2645 r1 = r0.m6961();
        AbstractC2651 r2 = r0.f8987;
        if (r2 != null) {
            C2628 contentType = r2.contentType();
            if (contentType != null) {
                r1.m6966(GraphRequest.CONTENT_TYPE_HEADER, contentType.f8933);
            }
            long contentLength = r2.contentLength();
            if (contentLength != -1) {
                r1.m6966("Content-Length", Long.toString(contentLength));
                r1.f8988.m6999("Transfer-Encoding");
            } else {
                r1.m6966("Transfer-Encoding", "chunked");
                r1.f8988.m6999("Content-Length");
            }
        }
        if (r0.f8982.m6996("Host") == null) {
            r1.m6966("Host", C2540.m6643(r0.f8985, false));
        }
        if (r0.f8982.m6996("Connection") == null) {
            r1.m6966("Connection", "Keep-Alive");
        }
        if (r0.f8982.m6996("Accept-Encoding") == null && r0.f8982.m6996("Range") == null) {
            r1.m6966("Accept-Encoding", "gzip");
            z = true;
        } else {
            z = false;
        }
        List<C2646> r7 = ((AbstractC2669.C2670) this.f8688).m7004(r0.f8985);
        if (!r7.isEmpty()) {
            StringBuilder sb = new StringBuilder();
            int size = r7.size();
            for (int i = 0; i < size; i++) {
                if (i > 0) {
                    sb.append("; ");
                }
                C2646 r12 = r7.get(i);
                sb.append(r12.f9002);
                sb.append('=');
                sb.append(r12.f9000);
            }
            r1.m6966("Cookie", sb.toString());
        }
        if (r0.f8982.m6996(GraphRequest.USER_AGENT_HEADER) == null) {
            r1.m6966(GraphRequest.USER_AGENT_HEADER, "okhttp/3.11.0");
        }
        C2671 r152 = r15.m6790(r1.m6970(), r15.f8693, r15.f8689, r15.f8699);
        C2577.m6784(this.f8688, r0.f8985, r152.f9088);
        C2671.C2672 k2 = new C2671.C2672(r152);
        k2.f9101 = r0;
        if (z) {
            String r02 = r152.f9088.m6996(GraphRequest.CONTENT_ENCODING_HEADER);
            if (r02 == null) {
                r02 = null;
            }
            if ("gzip".equalsIgnoreCase(r02) && C2577.m6780(r152)) {
                C1485 r03 = new C1485(r152.f9093.source());
                C2667.C2668 r8 = r152.f9088.m6997();
                r8.m6999(GraphRequest.CONTENT_ENCODING_HEADER);
                r8.m6999("Content-Length");
                List<String> list = r8.f9081;
                C2667.C2668 k3 = new C2667.C2668();
                Collections.addAll(k3.f9081, (String[]) list.toArray(new String[list.size()]));
                k2.f9104 = k3;
                String r153 = r152.f9088.m6996(GraphRequest.CONTENT_TYPE_HEADER);
                if (r153 == null) {
                    r153 = null;
                }
                k2.f9100 = new C2581(r153, -1, new C1488(r03));
            }
        }
        return k2.m7010();
    }
}
