package okhttp3.logging;

/* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
/* JADX INFO: loaded from: E:\ios\vf_dex\classes3.dex */
@kotlin.Metadata(d1 = {"\u0000L\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\"\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0005\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0006\u0018\u00002\u00020\u0001:\u0002\u001e\u001fB\u0011\b\u0007\u0012\b\b\u0002\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004J\u0010\u0010\u000e\u001a\u00020\u000f2\u0006\u0010\u0010\u001a\u00020\u0011H\u0002J\r\u0010\u000b\u001a\u00020\tH\u0007¢\u0006\u0002\b\u0012J\u0010\u0010\u0013\u001a\u00020\u00142\u0006\u0010\u0015\u001a\u00020\u0016H\u0016J\u0018\u0010\u0017\u001a\u00020\u00182\u0006\u0010\u0010\u001a\u00020\u00112\u0006\u0010\u0019\u001a\u00020\u001aH\u0002J\u000e\u0010\u001b\u001a\u00020\u00182\u0006\u0010\u001c\u001a\u00020\u0007J\u000e\u0010\u001d\u001a\u00020\u00002\u0006\u0010\n\u001a\u00020\tR\u0014\u0010\u0005\u001a\b\u0012\u0004\u0012\u00020\u00070\u0006X\u0082\u000e¢\u0006\u0002\n\u0000R$\u0010\n\u001a\u00020\t2\u0006\u0010\b\u001a\u00020\t@GX\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u000b\u0010\f\"\u0004\b\n\u0010\rR\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006 "}, d2 = {"Lokhttp3/logging/HttpLoggingInterceptor;", "Lokhttp3/Interceptor;", "logger", "Lokhttp3/logging/HttpLoggingInterceptor$Logger;", "(Lokhttp3/logging/HttpLoggingInterceptor$Logger;)V", "headersToRedact", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "<set-?>", "Lokhttp3/logging/HttpLoggingInterceptor$Level;", "level", "getLevel", "()Lokhttp3/logging/HttpLoggingInterceptor$Level;", "(Lokhttp3/logging/HttpLoggingInterceptor$Level;)V", "bodyHasUnknownEncoding", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "headers", "Lokhttp3/Headers;", "-deprecated_level", "intercept", "Lokhttp3/Response;", "chain", "Lokhttp3/Interceptor$Chain;", "logHeader", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "i", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "redactHeader", "name", "setLevel", "Level", "Logger", "okhttp-logging-interceptor"}, k = 1, mv = {1, 8, 0}, xi = 48)
public final class HttpLoggingInterceptor implements okhttp3.Interceptor {

    @org.jetbrains.annotations.NotNull
    private volatile java.util.Set<java.lang.String> headersToRedact;

    @org.jetbrains.annotations.NotNull
    private volatile okhttp3.logging.HttpLoggingInterceptor.Level level;

    @org.jetbrains.annotations.NotNull
    private final okhttp3.logging.HttpLoggingInterceptor.Logger logger;

    /* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
    @kotlin.Metadata(d1 = {"\u0000\f\n\u0002\u0018\u0002\n\u0002\u0010\u0010\n\u0002\b\u0006\b\u0086\u0001\u0018\u00002\b\u0012\u0004\u0012\u00020\u00000\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002j\u0002\b\u0003j\u0002\b\u0004j\u0002\b\u0005j\u0002\b\u0006¨\u0006\u0007"}, d2 = {"Lokhttp3/logging/HttpLoggingInterceptor$Level;", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "(Ljava/lang/String;I)V", "NONE", "BASIC", "HEADERS", "BODY", "okhttp-logging-interceptor"}, k = 1, mv = {1, 8, 0}, xi = 48)
    public enum Level {
        NONE,
        BASIC,
        HEADERS,
        BODY
    }

    /* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
    @kotlin.Metadata(d1 = {"\u0000\u0018\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\u000e\n\u0002\b\u0002\bæ\u0080\u0001\u0018\u0000 \u00062\u00020\u0001:\u0001\u0006J\u0010\u0010\u0002\u001a\u00020\u00032\u0006\u0010\u0004\u001a\u00020\u0005H&¨\u0006\u0007"}, d2 = {"Lokhttp3/logging/HttpLoggingInterceptor$Logger;", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "log", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "message", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "Companion", "okhttp-logging-interceptor"}, k = 1, mv = {1, 8, 0}, xi = 48)
    public interface Logger {

        /* JADX INFO: renamed from: Companion, reason: from kotlin metadata */
        @org.jetbrains.annotations.NotNull
        public static final okhttp3.logging.HttpLoggingInterceptor.Logger.Companion INSTANCE = okhttp3.logging.HttpLoggingInterceptor.Logger.Companion.$$INSTANCE;

        @kotlin.jvm.JvmField
        @org.jetbrains.annotations.NotNull
        public static final okhttp3.logging.HttpLoggingInterceptor.Logger DEFAULT = new okhttp3.logging.HttpLoggingInterceptor.Logger.Companion.DefaultLogger();

        /* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
        @kotlin.Metadata(d1 = {"\u0000\u0014\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\b\u0086\u0003\u0018\u00002\u00020\u0001:\u0001\u0005B\u0007\b\u0002¢\u0006\u0002\u0010\u0002R\u0013\u0010\u0003\u001a\u00020\u00048\u0006X\u0087\u0004¢\u0006\u0002\n\u0000¨\u0006\u0001¨\u0006\u0006"}, d2 = {"Lokhttp3/logging/HttpLoggingInterceptor$Logger$Companion;", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "()V", "DEFAULT", "Lokhttp3/logging/HttpLoggingInterceptor$Logger;", "DefaultLogger", "okhttp-logging-interceptor"}, k = 1, mv = {1, 8, 0}, xi = 48)
        public static final class Companion {
            static final /* synthetic */ okhttp3.logging.HttpLoggingInterceptor.Logger.Companion $$INSTANCE = new okhttp3.logging.HttpLoggingInterceptor.Logger.Companion();

            /* JADX INFO: compiled from: r8-map-id-ae6aab8d9a1033945587ffdd1bc6222159522c1d66e66a2c4cecb065134dd0a6 */
            @kotlin.Metadata(d1 = {"\u0000\u0018\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\u000e\n\u0000\b\u0002\u0018\u00002\u00020\u0001B\u0005¢\u0006\u0002\u0010\u0002J\u0010\u0010\u0003\u001a\u00020\u00042\u0006\u0010\u0005\u001a\u00020\u0006H\u0016¨\u0006\u0007"}, d2 = {"Lokhttp3/logging/HttpLoggingInterceptor$Logger$Companion$DefaultLogger;", "Lokhttp3/logging/HttpLoggingInterceptor$Logger;", "()V", "log", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "message", okhttp3.HttpUrl.FRAGMENT_ENCODE_SET, "okhttp-logging-interceptor"}, k = 1, mv = {1, 8, 0}, xi = 48)
            private static final class DefaultLogger implements okhttp3.logging.HttpLoggingInterceptor.Logger {
                @Override // okhttp3.logging.HttpLoggingInterceptor.Logger
                public void log(@org.jetbrains.annotations.NotNull java.lang.String message) {
                    kotlin.jvm.internal.Intrinsics.l(message, "message");
                    okhttp3.internal.platform.Platform.log$default(okhttp3.internal.platform.Platform.INSTANCE.get(), message, 0, null, 6, null);
                }
            }

            private Companion() {
            }
        }

        void log(@org.jetbrains.annotations.NotNull java.lang.String message);
    }

    /* JADX WARN: Illegal instructions before constructor call */
    @kotlin.jvm.JvmOverloads
    public HttpLoggingInterceptor() {
        okhttp3.logging.HttpLoggingInterceptor.Logger logger = null;
        this(logger, 1, logger);
    }

    private final boolean bodyHasUnknownEncoding(okhttp3.Headers headers) {
        java.lang.String str = headers.get("Content-Encoding");
        return (str == null || kotlin.text.StringsKt.K(str, "identity", true) || kotlin.text.StringsKt.K(str, "gzip", true)) ? false : true;
    }

    private final void logHeader(okhttp3.Headers headers, int i) {
        java.lang.String strValue = this.headersToRedact.contains(headers.name(i)) ? "██" : headers.value(i);
        this.logger.log(headers.name(i) + ": " + strValue);
    }

    @kotlin.Deprecated
    @kotlin.jvm.JvmName
    @org.jetbrains.annotations.NotNull
    /* JADX INFO: renamed from: -deprecated_level, reason: not valid java name and from getter */
    public final okhttp3.logging.HttpLoggingInterceptor.Level getLevel() {
        return this.level;
    }

    @org.jetbrains.annotations.NotNull
    public final okhttp3.logging.HttpLoggingInterceptor.Level getLevel() {
        return this.level;
    }

    @Override // okhttp3.Interceptor
    @org.jetbrains.annotations.NotNull
    public okhttp3.Response intercept(@org.jetbrains.annotations.NotNull okhttp3.Interceptor.Chain chain) throws java.lang.Exception {
        java.lang.String string;
        long j;
        char c;
        java.lang.String string2;
        java.nio.charset.Charset charset;
        java.nio.charset.Charset charset2;
        kotlin.jvm.internal.Intrinsics.l(chain, "chain");
        okhttp3.logging.HttpLoggingInterceptor.Level level = this.level;
        okhttp3.Request request = chain.request();
        if (level == okhttp3.logging.HttpLoggingInterceptor.Level.NONE) {
            return chain.proceed(request);
        }
        boolean z = level == okhttp3.logging.HttpLoggingInterceptor.Level.BODY;
        boolean z4 = z || level == okhttp3.logging.HttpLoggingInterceptor.Level.HEADERS;
        okhttp3.RequestBody requestBodyBody = request.body();
        okhttp3.Connection connection = chain.connection();
        java.lang.StringBuilder sb = new java.lang.StringBuilder();
        sb.append("--> ");
        sb.append(request.method());
        sb.append(' ');
        sb.append(request.url());
        if (connection != null) {
            java.lang.StringBuilder sb2 = new java.lang.StringBuilder();
            sb2.append(' ');
            sb2.append(connection.protocol());
            string = sb2.toString();
        } else {
            string = okhttp3.HttpUrl.FRAGMENT_ENCODE_SET;
        }
        sb.append(string);
        java.lang.String string3 = sb.toString();
        if (!z4 && requestBodyBody != null) {
            string3 = string3 + " (" + requestBodyBody.contentLength() + "-byte body)";
        }
        this.logger.log(string3);
        if (z4) {
            okhttp3.Headers headers = request.headers();
            j = -1;
            if (requestBodyBody != null) {
                okhttp3.MediaType contentType = requestBodyBody.getContentType();
                if (contentType != null && headers.get("Content-Type") == null) {
                    this.logger.log("Content-Type: " + contentType);
                }
                if (requestBodyBody.contentLength() != -1 && headers.get("Content-Length") == null) {
                    this.logger.log("Content-Length: " + requestBodyBody.contentLength());
                }
            }
            int size = headers.size();
            for (int i = 0; i < size; i++) {
                logHeader(headers, i);
            }
            if (!z || requestBodyBody == null) {
                this.logger.log("--> END " + request.method());
            } else if (bodyHasUnknownEncoding(request.headers())) {
                this.logger.log("--> END " + request.method() + " (encoded body omitted)");
            } else if (requestBodyBody.isDuplex()) {
                this.logger.log("--> END " + request.method() + " (duplex request body omitted)");
            } else if (requestBodyBody.isOneShot()) {
                this.logger.log("--> END " + request.method() + " (one-shot body omitted)");
            } else {
                okio.Buffer buffer = new okio.Buffer();
                requestBodyBody.writeTo(buffer);
                okhttp3.MediaType contentType2 = requestBodyBody.getContentType();
                if (contentType2 == null || (charset2 = contentType2.charset(java.nio.charset.StandardCharsets.UTF_8)) == null) {
                    charset2 = java.nio.charset.StandardCharsets.UTF_8;
                    kotlin.jvm.internal.Intrinsics.k(charset2, "UTF_8");
                }
                this.logger.log(okhttp3.HttpUrl.FRAGMENT_ENCODE_SET);
                if (okhttp3.logging.Utf8Kt.isProbablyUtf8(buffer)) {
                    this.logger.log(buffer.K0(charset2));
                    this.logger.log("--> END " + request.method() + " (" + requestBodyBody.contentLength() + "-byte body)");
                } else {
                    this.logger.log("--> END " + request.method() + " (binary " + requestBodyBody.contentLength() + "-byte body omitted)");
                }
            }
        } else {
            j = -1;
        }
        long jNanoTime = java.lang.System.nanoTime();
        try {
            okhttp3.Response responseProceed = chain.proceed(request);
            long millis = java.util.concurrent.TimeUnit.NANOSECONDS.toMillis(java.lang.System.nanoTime() - jNanoTime);
            okhttp3.ResponseBody responseBodyBody = responseProceed.body();
            kotlin.jvm.internal.Intrinsics.i(responseBodyBody);
            long contentLength = responseBodyBody.getContentLength();
            java.lang.String str = contentLength != j ? contentLength + "-byte" : "unknown-length";
            okhttp3.logging.HttpLoggingInterceptor.Logger logger = this.logger;
            java.lang.StringBuilder sb3 = new java.lang.StringBuilder();
            boolean z5 = z4;
            sb3.append("<-- ");
            sb3.append(responseProceed.code());
            if (responseProceed.message().length() == 0) {
                string2 = okhttp3.HttpUrl.FRAGMENT_ENCODE_SET;
                c = ' ';
            } else {
                java.lang.String strMessage = responseProceed.message();
                java.lang.StringBuilder sb4 = new java.lang.StringBuilder();
                c = ' ';
                sb4.append(' ');
                sb4.append(strMessage);
                string2 = sb4.toString();
            }
            sb3.append(string2);
            sb3.append(c);
            sb3.append(responseProceed.request().url());
            sb3.append(" (");
            sb3.append(millis);
            sb3.append("ms");
            sb3.append(z5 ? okhttp3.HttpUrl.FRAGMENT_ENCODE_SET : ", " + str + " body");
            sb3.append(')');
            logger.log(sb3.toString());
            if (z5) {
                okhttp3.Headers headers2 = responseProceed.headers();
                int size2 = headers2.size();
                for (int i2 = 0; i2 < size2; i2++) {
                    logHeader(headers2, i2);
                }
                if (z && okhttp3.internal.http.HttpHeaders.promisesBody(responseProceed)) {
                    if (bodyHasUnknownEncoding(responseProceed.headers())) {
                        this.logger.log("<-- END HTTP (encoded body omitted)");
                        return responseProceed;
                    }
                    okio.BufferedSource bodySource = responseBodyBody.getBodySource();
                    bodySource.request(Long.MAX_VALUE);
                    okio.Buffer bufferField = bodySource.getBufferField();
                    java.lang.Long l = null;
                    if (kotlin.text.StringsKt.K("gzip", headers2.get("Content-Encoding"), true)) {
                        java.lang.Long lValueOf = java.lang.Long.valueOf(bufferField.getSize());
                        okio.GzipSource gzipSource = new okio.GzipSource(bufferField.clone());
                        try {
                            bufferField = new okio.Buffer();
                            bufferField.L1(gzipSource);
                            kotlin.io.CloseableKt.a(gzipSource, (java.lang.Throwable) null);
                            l = lValueOf;
                        } catch (java.lang.Throwable th) {
                            try {
                                throw th;
                            } catch (java.lang.Throwable th2) {
                                kotlin.io.CloseableKt.a(gzipSource, th);
                                throw th2;
                            }
                        }
                    }
                    okhttp3.MediaType mediaType = responseBodyBody.get$contentType();
                    if (mediaType == null || (charset = mediaType.charset(java.nio.charset.StandardCharsets.UTF_8)) == null) {
                        charset = java.nio.charset.StandardCharsets.UTF_8;
                        kotlin.jvm.internal.Intrinsics.k(charset, "UTF_8");
                    }
                    if (!okhttp3.logging.Utf8Kt.isProbablyUtf8(bufferField)) {
                        this.logger.log(okhttp3.HttpUrl.FRAGMENT_ENCODE_SET);
                        this.logger.log("<-- END HTTP (binary " + bufferField.getSize() + "-byte body omitted)");
                        return responseProceed;
                    }
                    if (contentLength != 0) {
                        this.logger.log(okhttp3.HttpUrl.FRAGMENT_ENCODE_SET);
                        this.logger.log(bufferField.clone().K0(charset));
                    }
                    if (l == null) {
                        this.logger.log("<-- END HTTP (" + bufferField.getSize() + "-byte body)");
                        return responseProceed;
                    }
                    this.logger.log("<-- END HTTP (" + bufferField.getSize() + "-byte, " + l + "-gzipped-byte body)");
                    return responseProceed;
                }
                this.logger.log("<-- END HTTP");
            }
            return responseProceed;
        } catch (java.lang.Exception e) {
            this.logger.log("<-- HTTP FAILED: " + e);
            throw e;
        }
    }

    @kotlin.jvm.JvmName
    public final void level(@org.jetbrains.annotations.NotNull okhttp3.logging.HttpLoggingInterceptor.Level level) {
        kotlin.jvm.internal.Intrinsics.l(level, "<set-?>");
        this.level = level;
    }

    public final void redactHeader(@org.jetbrains.annotations.NotNull java.lang.String name) {
        kotlin.jvm.internal.Intrinsics.l(name, "name");
        java.util.TreeSet treeSet = new java.util.TreeSet(kotlin.text.StringsKt.M(kotlin.jvm.internal.StringCompanionObject.a));
        kotlin.collections.CollectionsKt.E(treeSet, this.headersToRedact);
        treeSet.add(name);
        this.headersToRedact = treeSet;
    }

    @org.jetbrains.annotations.NotNull
    public final okhttp3.logging.HttpLoggingInterceptor setLevel(@org.jetbrains.annotations.NotNull okhttp3.logging.HttpLoggingInterceptor.Level level) {
        kotlin.jvm.internal.Intrinsics.l(level, "level");
        this.level = level;
        return this;
    }

    @kotlin.jvm.JvmOverloads
    public HttpLoggingInterceptor(@org.jetbrains.annotations.NotNull okhttp3.logging.HttpLoggingInterceptor.Logger logger) {
        kotlin.jvm.internal.Intrinsics.l(logger, "logger");
        this.logger = logger;
        this.headersToRedact = kotlin.collections.SetsKt.e();
        this.level = okhttp3.logging.HttpLoggingInterceptor.Level.NONE;
    }

    public /* synthetic */ HttpLoggingInterceptor(okhttp3.logging.HttpLoggingInterceptor.Logger logger, int i, kotlin.jvm.internal.DefaultConstructorMarker defaultConstructorMarker) {
        this((i & 1) != 0 ? okhttp3.logging.HttpLoggingInterceptor.Logger.DEFAULT : logger);
    }
}
