导航菜单

页面标题

页面副标题

Zepto v25.1.4 - HttpTransaction.java 源代码

正在查看: Zepto v25.1.4 应用的 HttpTransaction.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.chuckerteam.chucker.internal.data.entity;

import android.R;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.PrimaryKey;
import com.chuckerteam.chucker.internal.support.FormatUtils;
import com.chuckerteam.chucker.internal.support.FormattedUrl;
import com.chuckerteam.chucker.internal.support.JsonConverter;
import com.google.gson.JsonParseException;
import com.google.gson.JsonParser;
import com.google.gson.reflect.TypeToken;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.StringWriter;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import kotlin.Metadata;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import kotlin.text.StringsKt;
import okhttp3.Headers;
import okhttp3.HttpUrl;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.w3c.dom.Document;
import org.xml.sax.InputSource;
import org.xml.sax.SAXParseException;

@Entity
@Metadata
public final class HttpTransaction {

    @ColumnInfo
    @Nullable
    private String error;

    @ColumnInfo
    @Nullable
    private String host;

    @PrimaryKey
    @ColumnInfo
    private long id;

    @ColumnInfo
    private boolean isRequestBodyPlainText;

    @ColumnInfo
    private boolean isResponseBodyPlainText;

    @ColumnInfo
    @Nullable
    private String method;

    @ColumnInfo
    @Nullable
    private String path;

    @ColumnInfo
    @Nullable
    private String protocol;

    @ColumnInfo
    @Nullable
    private String requestBody;

    @ColumnInfo
    @Nullable
    private String requestContentType;

    @ColumnInfo
    @Nullable
    private Long requestDate;

    @ColumnInfo
    @Nullable
    private String requestHeaders;

    @ColumnInfo
    @Nullable
    private Long requestPayloadSize;

    @ColumnInfo
    @Nullable
    private String responseBody;

    @ColumnInfo
    @Nullable
    private String responseCipherSuite;

    @ColumnInfo
    @Nullable
    private Integer responseCode;

    @ColumnInfo
    @Nullable
    private String responseContentType;

    @ColumnInfo
    @Nullable
    private Long responseDate;

    @ColumnInfo
    @Nullable
    private String responseHeaders;

    @ColumnInfo
    @Nullable
    private byte[] responseImageData;

    @ColumnInfo
    @Nullable
    private String responseMessage;

    @ColumnInfo
    @Nullable
    private Long responsePayloadSize;

    @ColumnInfo
    @Nullable
    private String responseTlsVersion;

    @ColumnInfo
    @Nullable
    private String scheme;

    @ColumnInfo
    @Nullable
    private Long tookMs;

    @ColumnInfo
    @Nullable
    private String url;

    @Metadata
    public static final class Status {

        public static final Status f11325a;

        public static final Status f11326b;

        public static final Status f11327c;
        public static final Status[] d;

        static {
            Status status = new Status("Requested", 0);
            f11325a = status;
            Status status2 = new Status("Complete", 1);
            f11326b = status2;
            Status status3 = new Status("Failed", 2);
            f11327c = status3;
            d = new Status[]{status, status2, status3};
        }

        public static Status valueOf(String str) {
            return (Status) Enum.valueOf(Status.class, str);
        }

        public static Status[] values() {
            return (Status[]) d.clone();
        }
    }

    @Metadata
    public class WhenMappings {
        static {
            int[] iArr = new int[Status.values().length];
            iArr[2] = 1;
            iArr[0] = 2;
        }
    }

    public HttpTransaction(long j, @Nullable Long l, @Nullable Long l2, @Nullable Long l3, @Nullable String str, @Nullable String str2, @Nullable String str3, @Nullable String str4, @Nullable String str5, @Nullable String str6, @Nullable String str7, @Nullable String str8, @Nullable Long l4, @Nullable String str9, @Nullable String str10, @Nullable String str11, boolean z, @Nullable Integer num, @Nullable String str12, @Nullable String str13, @Nullable Long l5, @Nullable String str14, @Nullable String str15, @Nullable String str16, boolean z2, @Nullable byte[] bArr) {
        this.id = j;
        this.requestDate = l;
        this.responseDate = l2;
        this.tookMs = l3;
        this.protocol = str;
        this.method = str2;
        this.url = str3;
        this.host = str4;
        this.path = str5;
        this.scheme = str6;
        this.responseTlsVersion = str7;
        this.responseCipherSuite = str8;
        this.requestPayloadSize = l4;
        this.requestContentType = str9;
        this.requestHeaders = str10;
        this.requestBody = str11;
        this.isRequestBodyPlainText = z;
        this.responseCode = num;
        this.responseMessage = str12;
        this.error = str13;
        this.responsePayloadSize = l5;
        this.responseContentType = str14;
        this.responseHeaders = str15;
        this.responseBody = str16;
        this.isResponseBodyPlainText = z2;
        this.responseImageData = bArr;
    }

    private final String formatBody(String str, String str2) {
        String stringWriter;
        if (str2 == null || StringsKt.w(str2)) {
            return str;
        }
        if (StringsKt.m(str2, "json", true)) {
            Intrinsics.checkNotNullParameter(str, "json");
            try {
                stringWriter = JsonConverter.a().i(JsonParser.b(str));
                Intrinsics.checkNotNullExpressionValue(stringWriter, "{\n            val je = JsonParser.parseString(json)\n            JsonConverter.instance.toJson(je)\n        }");
            } catch (JsonParseException | IOException | TransformerException | SAXParseException unused) {
                return str;
            }
        } else {
            if (!StringsKt.m(str2, "xml", true)) {
                return StringsKt.m(str2, "x-www-form-urlencoded", true) ? FormatUtils.c(str) : str;
            }
            Intrinsics.checkNotNullParameter(str, "xml");
            DocumentBuilderFactory newInstance = DocumentBuilderFactory.newInstance();
            Intrinsics.checkNotNullExpressionValue(newInstance, "newInstance()");
            newInstance.setExpandEntityReferences(false);
            DocumentBuilder newDocumentBuilder = newInstance.newDocumentBuilder();
            Intrinsics.checkNotNullExpressionValue(newDocumentBuilder, "documentFactory.newDocumentBuilder()");
            Charset defaultCharset = Charset.defaultCharset();
            Intrinsics.checkNotNullExpressionValue(defaultCharset, "defaultCharset()");
            byte[] bytes = str.getBytes(defaultCharset);
            Intrinsics.checkNotNullExpressionValue(bytes, "(this as java.lang.String).getBytes(charset)");
            Document parse = newDocumentBuilder.parse(new InputSource(new ByteArrayInputStream(bytes)));
            Intrinsics.checkNotNullExpressionValue(parse, "documentBuilder.parse(inputSource)");
            DOMSource dOMSource = new DOMSource(parse);
            StringWriter stringWriter2 = new StringWriter();
            StreamResult streamResult = new StreamResult(stringWriter2);
            TransformerFactory newInstance2 = TransformerFactory.newInstance();
            newInstance2.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
            Transformer newTransformer = newInstance2.newTransformer();
            newTransformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
            newTransformer.setOutputProperty("indent", "yes");
            newTransformer.transform(dOMSource, streamResult);
            stringWriter = stringWriter2.toString();
            Intrinsics.checkNotNullExpressionValue(stringWriter, "{\n            val documentFactory: DocumentBuilderFactory = DocumentBuilderFactory.newInstance()\n            // This flag is required for security reasons\n            documentFactory.isExpandEntityReferences = false\n\n            val documentBuilder: DocumentBuilder = documentFactory.newDocumentBuilder()\n            val inputSource = InputSource(ByteArrayInputStream(xml.toByteArray(Charset.defaultCharset())))\n            val document: Document = documentBuilder.parse(inputSource)\n\n            val domSource = DOMSource(document)\n            val writer = StringWriter()\n            val result = StreamResult(writer)\n\n            TransformerFactory.newInstance().apply {\n                setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true)\n            }.newTransformer().apply {\n                setOutputProperty(\"{http://xml.apache.org/xslt}indent-amount\", \"2\")\n                setOutputProperty(OutputKeys.INDENT, \"yes\")\n                transform(domSource, result)\n            }\n            writer.toString()\n        }");
        }
        return stringWriter;
    }

    private final String formatBytes(long j) {
        return FormatUtils.a(j);
    }

    private final List<HttpHeader> toHttpHeaderList(Headers headers) {
        ArrayList arrayList = new ArrayList();
        int size = headers.size();
        if (size > 0) {
            int i = 0;
            while (true) {
                int i2 = i + 1;
                String b2 = headers.b(i);
                Intrinsics.checkNotNullExpressionValue(b2, "headers.name(i)");
                String k = headers.k(i);
                Intrinsics.checkNotNullExpressionValue(k, "headers.value(i)");
                arrayList.add(new HttpHeader(b2, k));
                if (i2 >= size) {
                    break;
                }
                i = i2;
            }
        }
        return arrayList;
    }

    @Nullable
    public final String getDurationString() {
        Long l = this.tookMs;
        if (l == null) {
            return null;
        }
        return l.longValue() + " ms";
    }

    @Nullable
    public final String getError() {
        return this.error;
    }

    @NotNull
    public final String getFormattedPath(boolean z) {
        String str = this.url;
        HttpUrl c2 = str == null ? null : HttpUrl.Companion.c(str);
        return c2 == null ? "" : FormattedUrl.Companion.a(c2, z).a();
    }

    @NotNull
    public final String getFormattedRequestBody() {
        String formatBody;
        String str = this.requestBody;
        return (str == null || (formatBody = formatBody(str, getRequestContentType())) == null) ? "" : formatBody;
    }

    @NotNull
    public final String getFormattedResponseBody() {
        String formatBody;
        String str = this.responseBody;
        return (str == null || (formatBody = formatBody(str, getResponseContentType())) == null) ? "" : formatBody;
    }

    @NotNull
    public final String getFormattedUrl(boolean z) {
        String str = this.url;
        HttpUrl c2 = str == null ? null : HttpUrl.Companion.c(str);
        return c2 == null ? "" : FormattedUrl.Companion.a(c2, z).b();
    }

    @Nullable
    public final String getHost() {
        return this.host;
    }

    public final long getId() {
        return this.id;
    }

    @Nullable
    public final String getMethod() {
        return this.method;
    }

    @NotNull
    public final String getNotificationText() {
        int ordinal = getStatus().ordinal();
        if (ordinal == 0) {
            return " . . .  " + ((Object) this.method) + ' ' + ((Object) this.path);
        }
        if (ordinal == 2) {
            return " ! ! !  " + ((Object) this.method) + ' ' + ((Object) this.path);
        }
        StringBuilder sb = new StringBuilder();
        sb.append(this.responseCode);
        sb.append(' ');
        sb.append((Object) this.method);
        sb.append(' ');
        sb.append((Object) this.path);
        return sb.toString();
    }

    @Nullable
    public final List<HttpHeader> getParsedRequestHeaders() {
        return (List) JsonConverter.a().e(this.requestHeaders, ((TypeToken) new HttpTransaction$getParsedRequestHeaders$1()).b);
    }

    @Nullable
    public final List<HttpHeader> getParsedResponseHeaders() {
        return (List) JsonConverter.a().e(this.responseHeaders, ((TypeToken) new HttpTransaction$getParsedResponseHeaders$1()).b);
    }

    @Nullable
    public final String getPath() {
        return this.path;
    }

    @Nullable
    public final String getProtocol() {
        return this.protocol;
    }

    @Nullable
    public final String getRequestBody() {
        return this.requestBody;
    }

    @Nullable
    public final String getRequestContentType() {
        return this.requestContentType;
    }

    @Nullable
    public final Long getRequestDate() {
        return this.requestDate;
    }

    @Nullable
    public final String getRequestDateString() {
        Long l = this.requestDate;
        if (l == null) {
            return null;
        }
        return new Date(l.longValue()).toString();
    }

    @Nullable
    public final String getRequestHeaders() {
        return this.requestHeaders;
    }

    @NotNull
    public final String getRequestHeadersString(boolean z) {
        return FormatUtils.b(getParsedRequestHeaders(), z);
    }

    @Nullable
    public final Long getRequestPayloadSize() {
        return this.requestPayloadSize;
    }

    @NotNull
    public final String getRequestSizeString() {
        Long l = this.requestPayloadSize;
        return formatBytes(l == null ? 0L : l.longValue());
    }

    @Nullable
    public final String getResponseBody() {
        return this.responseBody;
    }

    @Nullable
    public final String getResponseCipherSuite() {
        return this.responseCipherSuite;
    }

    @Nullable
    public final Integer getResponseCode() {
        return this.responseCode;
    }

    @Nullable
    public final String getResponseContentType() {
        return this.responseContentType;
    }

    @Nullable
    public final Long getResponseDate() {
        return this.responseDate;
    }

    @Nullable
    public final String getResponseDateString() {
        Long l = this.responseDate;
        if (l == null) {
            return null;
        }
        return new Date(l.longValue()).toString();
    }

    @Nullable
    public final String getResponseHeaders() {
        return this.responseHeaders;
    }

    @NotNull
    public final String getResponseHeadersString(boolean z) {
        return FormatUtils.b(getParsedResponseHeaders(), z);
    }

    @Nullable
    public final Bitmap getResponseImageBitmap() {
        byte[] bArr = this.responseImageData;
        if (bArr == null) {
            return null;
        }
        return BitmapFactory.decodeByteArray(bArr, 0, bArr.length);
    }

    @Nullable
    public final byte[] getResponseImageData() {
        return this.responseImageData;
    }

    @Nullable
    public final String getResponseMessage() {
        return this.responseMessage;
    }

    @Nullable
    public final Long getResponsePayloadSize() {
        return this.responsePayloadSize;
    }

    @Nullable
    public final String getResponseSizeString() {
        Long l = this.responsePayloadSize;
        if (l == null) {
            return null;
        }
        return formatBytes(l.longValue());
    }

    @Nullable
    public final String getResponseSummaryText() {
        int ordinal = getStatus().ordinal();
        if (ordinal == 0) {
            return null;
        }
        if (ordinal == 2) {
            return this.error;
        }
        StringBuilder sb = new StringBuilder();
        sb.append(this.responseCode);
        sb.append(' ');
        sb.append((Object) this.responseMessage);
        return sb.toString();
    }

    @Nullable
    public final String getResponseTlsVersion() {
        return this.responseTlsVersion;
    }

    @Nullable
    public final String getScheme() {
        return this.scheme;
    }

    @NotNull
    public final Status getStatus() {
        return this.error != null ? Status.f11327c : this.responseCode == null ? Status.f11325a : Status.f11326b;
    }

    @Nullable
    public final Long getTookMs() {
        return this.tookMs;
    }

    @NotNull
    public final String getTotalSizeString() {
        Long l = this.requestPayloadSize;
        long longValue = l == null ? 0L : l.longValue();
        Long l2 = this.responsePayloadSize;
        return formatBytes(longValue + (l2 != null ? l2.longValue() : 0L));
    }

    @Nullable
    public final String getUrl() {
        return this.url;
    }

    public final boolean hasTheSameContent(@Nullable HttpTransaction httpTransaction) {
        if (this == httpTransaction) {
            return true;
        }
        if (httpTransaction != null && this.id == httpTransaction.id && Intrinsics.c(this.requestDate, httpTransaction.requestDate) && Intrinsics.c(this.responseDate, httpTransaction.responseDate) && Intrinsics.c(this.tookMs, httpTransaction.tookMs) && Intrinsics.c(this.protocol, httpTransaction.protocol) && Intrinsics.c(this.method, httpTransaction.method) && Intrinsics.c(this.url, httpTransaction.url) && Intrinsics.c(this.host, httpTransaction.host) && Intrinsics.c(this.path, httpTransaction.path) && Intrinsics.c(this.scheme, httpTransaction.scheme) && Intrinsics.c(this.responseTlsVersion, httpTransaction.responseTlsVersion) && Intrinsics.c(this.responseCipherSuite, httpTransaction.responseCipherSuite) && Intrinsics.c(this.requestPayloadSize, httpTransaction.requestPayloadSize) && Intrinsics.c(this.requestContentType, httpTransaction.requestContentType) && Intrinsics.c(this.requestHeaders, httpTransaction.requestHeaders) && Intrinsics.c(this.requestBody, httpTransaction.requestBody) && this.isRequestBodyPlainText == httpTransaction.isRequestBodyPlainText && Intrinsics.c(this.responseCode, httpTransaction.responseCode) && Intrinsics.c(this.responseMessage, httpTransaction.responseMessage) && Intrinsics.c(this.error, httpTransaction.error) && Intrinsics.c(this.responsePayloadSize, httpTransaction.responsePayloadSize) && Intrinsics.c(this.responseContentType, httpTransaction.responseContentType) && Intrinsics.c(this.responseHeaders, httpTransaction.responseHeaders) && Intrinsics.c(this.responseBody, httpTransaction.responseBody) && this.isResponseBodyPlainText == httpTransaction.isResponseBodyPlainText) {
            byte[] bArr = this.responseImageData;
            if (bArr == null) {
                return true;
            }
            byte[] bArr2 = httpTransaction.responseImageData;
            if (bArr2 == null) {
                bArr2 = new byte[0];
            }
            if (Arrays.equals(bArr, bArr2)) {
                return true;
            }
        }
        return false;
    }

    public final boolean isRequestBodyPlainText() {
        return this.isRequestBodyPlainText;
    }

    public final boolean isResponseBodyPlainText() {
        return this.isResponseBodyPlainText;
    }

    public final boolean isSsl() {
        return StringsKt.r(this.scheme, "https", true);
    }

    @NotNull
    public final HttpTransaction populateUrl(@NotNull HttpUrl httpUrl) {
        Intrinsics.checkNotNullParameter(httpUrl, "httpUrl");
        FormattedUrl a2 = FormattedUrl.Companion.a(httpUrl, false);
        this.url = a2.b();
        this.host = a2.f11380b;
        this.path = a2.a();
        this.scheme = a2.f11379a;
        return this;
    }

    public final void setError(@Nullable String str) {
        this.error = str;
    }

    public final void setHost(@Nullable String str) {
        this.host = str;
    }

    public final void setId(long j) {
        this.id = j;
    }

    public final void setMethod(@Nullable String str) {
        this.method = str;
    }

    public final void setPath(@Nullable String str) {
        this.path = str;
    }

    public final void setProtocol(@Nullable String str) {
        this.protocol = str;
    }

    public final void setRequestBody(@Nullable String str) {
        this.requestBody = str;
    }

    public final void setRequestBodyPlainText(boolean z) {
        this.isRequestBodyPlainText = z;
    }

    public final void setRequestContentType(@Nullable String str) {
        this.requestContentType = str;
    }

    public final void setRequestDate(@Nullable Long l) {
        this.requestDate = l;
    }

    public final void setRequestHeaders(@Nullable String str) {
        this.requestHeaders = str;
    }

    public final void setRequestPayloadSize(@Nullable Long l) {
        this.requestPayloadSize = l;
    }

    public final void setResponseBody(@Nullable String str) {
        this.responseBody = str;
    }

    public final void setResponseBodyPlainText(boolean z) {
        this.isResponseBodyPlainText = z;
    }

    public final void setResponseCipherSuite(@Nullable String str) {
        this.responseCipherSuite = str;
    }

    public final void setResponseCode(@Nullable Integer num) {
        this.responseCode = num;
    }

    public final void setResponseContentType(@Nullable String str) {
        this.responseContentType = str;
    }

    public final void setResponseDate(@Nullable Long l) {
        this.responseDate = l;
    }

    public final void setResponseHeaders(@Nullable String str) {
        this.responseHeaders = str;
    }

    public final void setResponseImageData(@Nullable byte[] bArr) {
        this.responseImageData = bArr;
    }

    public final void setResponseMessage(@Nullable String str) {
        this.responseMessage = str;
    }

    public final void setResponsePayloadSize(@Nullable Long l) {
        this.responsePayloadSize = l;
    }

    public final void setResponseTlsVersion(@Nullable String str) {
        this.responseTlsVersion = str;
    }

    public final void setScheme(@Nullable String str) {
        this.scheme = str;
    }

    public final void setTookMs(@Nullable Long l) {
        this.tookMs = l;
    }

    public final void setUrl(@Nullable String str) {
        this.url = str;
    }

    public HttpTransaction(long j, Long l, Long l2, Long l3, String str, String str2, String str3, String str4, String str5, String str6, String str7, String str8, Long l4, String str9, String str10, String str11, boolean z, Integer num, String str12, String str13, Long l5, String str14, String str15, String str16, boolean z2, byte[] bArr, int i, DefaultConstructorMarker defaultConstructorMarker) {
        this((i & 1) != 0 ? 0L : j, l, l2, l3, str, str2, str3, str4, str5, str6, str7, str8, l4, str9, str10, str11, (i & 65536) != 0 ? true : z, num, str12, str13, l5, str14, str15, str16, (i & 16777216) != 0 ? true : z2, bArr);
    }

    public final void setRequestHeaders(@NotNull Headers headers) {
        Intrinsics.checkNotNullParameter(headers, "headers");
        setRequestHeaders(toHttpHeaderList(headers));
    }

    public final void setResponseHeaders(@NotNull Headers headers) {
        Intrinsics.checkNotNullParameter(headers, "headers");
        setResponseHeaders(toHttpHeaderList(headers));
    }

    @Ignore
    public HttpTransaction() {
        this(0L, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, false, null, null, null, null, null, null, null, false, null, R.attr.label, null);
    }

    public final void setRequestHeaders(@NotNull List<HttpHeader> list) {
        Intrinsics.checkNotNullParameter(list, "headers");
        this.requestHeaders = JsonConverter.a().j(list);
    }

    public final void setResponseHeaders(@NotNull List<HttpHeader> list) {
        Intrinsics.checkNotNullParameter(list, "headers");
        this.responseHeaders = JsonConverter.a().j(list);
    }
}