Rabbit-R1/original r1/java/sources/okhttp3/internal/http2/Http2Reader.java
2024-05-21 17:08:36 -04:00

535 lines
29 KiB
Java

package okhttp3.internal.http2;
import io.sentry.ProfilingTraceData;
import io.sentry.SentryEnvelopeItemHeader;
import io.sentry.SentryEvent;
import io.sentry.protocol.SentryThread;
import io.sentry.protocol.TransactionInfo;
import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import kotlin.Metadata;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;
import okhttp3.internal.Util;
import okhttp3.internal.http2.Hpack;
import okio.Buffer;
import okio.BufferedSource;
import okio.ByteString;
import okio.Source;
import okio.Timeout;
/* compiled from: Http2Reader.kt */
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000H\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\b\n\u0002\b\u0004\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\f\u0018\u0000 #2\u00020\u0001:\u0003#$%B\u0015\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005¢\u0006\u0002\u0010\u0006J\b\u0010\u000b\u001a\u00020\fH\u0016J\u0016\u0010\r\u001a\u00020\u00052\u0006\u0010\u000e\u001a\u00020\u00052\u0006\u0010\u000f\u001a\u00020\u0010J\u000e\u0010\u0011\u001a\u00020\f2\u0006\u0010\u000f\u001a\u00020\u0010J(\u0010\u0012\u001a\u00020\f2\u0006\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0013\u001a\u00020\u00142\u0006\u0010\u0015\u001a\u00020\u00142\u0006\u0010\u0016\u001a\u00020\u0014H\u0002J(\u0010\u0017\u001a\u00020\f2\u0006\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0013\u001a\u00020\u00142\u0006\u0010\u0015\u001a\u00020\u00142\u0006\u0010\u0016\u001a\u00020\u0014H\u0002J.\u0010\u0018\u001a\b\u0012\u0004\u0012\u00020\u001a0\u00192\u0006\u0010\u0013\u001a\u00020\u00142\u0006\u0010\u001b\u001a\u00020\u00142\u0006\u0010\u0015\u001a\u00020\u00142\u0006\u0010\u0016\u001a\u00020\u0014H\u0002J(\u0010\u001c\u001a\u00020\f2\u0006\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0013\u001a\u00020\u00142\u0006\u0010\u0015\u001a\u00020\u00142\u0006\u0010\u0016\u001a\u00020\u0014H\u0002J(\u0010\u001d\u001a\u00020\f2\u0006\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0013\u001a\u00020\u00142\u0006\u0010\u0015\u001a\u00020\u00142\u0006\u0010\u0016\u001a\u00020\u0014H\u0002J\u0018\u0010\u001e\u001a\u00020\f2\u0006\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0016\u001a\u00020\u0014H\u0002J(\u0010\u001e\u001a\u00020\f2\u0006\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0013\u001a\u00020\u00142\u0006\u0010\u0015\u001a\u00020\u00142\u0006\u0010\u0016\u001a\u00020\u0014H\u0002J(\u0010\u001f\u001a\u00020\f2\u0006\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0013\u001a\u00020\u00142\u0006\u0010\u0015\u001a\u00020\u00142\u0006\u0010\u0016\u001a\u00020\u0014H\u0002J(\u0010 \u001a\u00020\f2\u0006\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0013\u001a\u00020\u00142\u0006\u0010\u0015\u001a\u00020\u00142\u0006\u0010\u0016\u001a\u00020\u0014H\u0002J(\u0010!\u001a\u00020\f2\u0006\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0013\u001a\u00020\u00142\u0006\u0010\u0015\u001a\u00020\u00142\u0006\u0010\u0016\u001a\u00020\u0014H\u0002J(\u0010\"\u001a\u00020\f2\u0006\u0010\u000f\u001a\u00020\u00102\u0006\u0010\u0013\u001a\u00020\u00142\u0006\u0010\u0015\u001a\u00020\u00142\u0006\u0010\u0016\u001a\u00020\u0014H\u0002R\u000e\u0010\u0004\u001a\u00020\u0005X\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0007\u001a\u00020\bX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\t\u001a\u00020\nX\u0082\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000¨\u0006&"}, d2 = {"Lokhttp3/internal/http2/Http2Reader;", "Ljava/io/Closeable;", TransactionInfo.JsonKeys.SOURCE, "Lokio/BufferedSource;", "client", "", "(Lokio/BufferedSource;Z)V", "continuation", "Lokhttp3/internal/http2/Http2Reader$ContinuationSource;", "hpackReader", "Lokhttp3/internal/http2/Hpack$Reader;", "close", "", "nextFrame", "requireSettings", "handler", "Lokhttp3/internal/http2/Http2Reader$Handler;", "readConnectionPreface", "readData", SentryEnvelopeItemHeader.JsonKeys.LENGTH, "", "flags", "streamId", "readGoAway", "readHeaderBlock", "", "Lokhttp3/internal/http2/Header;", "padding", "readHeaders", "readPing", "readPriority", "readPushPromise", "readRstStream", "readSettings", "readWindowUpdate", "Companion", "ContinuationSource", "Handler", "okhttp"}, k = 1, mv = {1, 4, 0})
/* loaded from: classes3.dex */
public final class Http2Reader implements Closeable {
/* renamed from: Companion, reason: from kotlin metadata */
public static final Companion INSTANCE = new Companion(null);
private static final Logger logger;
private final boolean client;
private final ContinuationSource continuation;
private final Hpack.Reader hpackReader;
private final BufferedSource source;
/* compiled from: Http2Reader.kt */
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000X\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\t\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0018\u0002\n\u0002\b\u0004\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u000e\n\u0002\u0018\u0002\n\u0002\b\u0003\bf\u0018\u00002\u00020\u0001J\b\u0010\u0002\u001a\u00020\u0003H&J8\u0010\u0004\u001a\u00020\u00032\u0006\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u0007\u001a\u00020\b2\u0006\u0010\t\u001a\u00020\n2\u0006\u0010\u000b\u001a\u00020\b2\u0006\u0010\f\u001a\u00020\u00062\u0006\u0010\r\u001a\u00020\u000eH&J(\u0010\u000f\u001a\u00020\u00032\u0006\u0010\u0010\u001a\u00020\u00112\u0006\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u0012\u001a\u00020\u00132\u0006\u0010\u0014\u001a\u00020\u0006H&J \u0010\u0015\u001a\u00020\u00032\u0006\u0010\u0016\u001a\u00020\u00062\u0006\u0010\u0017\u001a\u00020\u00182\u0006\u0010\u0019\u001a\u00020\nH&J.\u0010\u001a\u001a\u00020\u00032\u0006\u0010\u0010\u001a\u00020\u00112\u0006\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u001b\u001a\u00020\u00062\f\u0010\u001c\u001a\b\u0012\u0004\u0012\u00020\u001e0\u001dH&J \u0010\u001f\u001a\u00020\u00032\u0006\u0010 \u001a\u00020\u00112\u0006\u0010!\u001a\u00020\u00062\u0006\u0010\"\u001a\u00020\u0006H&J(\u0010#\u001a\u00020\u00032\u0006\u0010\u0005\u001a\u00020\u00062\u0006\u0010$\u001a\u00020\u00062\u0006\u0010%\u001a\u00020\u00062\u0006\u0010&\u001a\u00020\u0011H&J&\u0010'\u001a\u00020\u00032\u0006\u0010\u0005\u001a\u00020\u00062\u0006\u0010(\u001a\u00020\u00062\f\u0010)\u001a\b\u0012\u0004\u0012\u00020\u001e0\u001dH&J\u0018\u0010*\u001a\u00020\u00032\u0006\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u0017\u001a\u00020\u0018H&J\u0018\u0010+\u001a\u00020\u00032\u0006\u0010,\u001a\u00020\u00112\u0006\u0010+\u001a\u00020-H&J\u0018\u0010.\u001a\u00020\u00032\u0006\u0010\u0005\u001a\u00020\u00062\u0006\u0010/\u001a\u00020\u000eH&¨\u00060"}, d2 = {"Lokhttp3/internal/http2/Http2Reader$Handler;", "", "ackSettings", "", "alternateService", "streamId", "", "origin", "", "protocol", "Lokio/ByteString;", "host", "port", "maxAge", "", "data", "inFinished", "", TransactionInfo.JsonKeys.SOURCE, "Lokio/BufferedSource;", SentryEnvelopeItemHeader.JsonKeys.LENGTH, "goAway", "lastGoodStreamId", "errorCode", "Lokhttp3/internal/http2/ErrorCode;", "debugData", "headers", "associatedStreamId", "headerBlock", "", "Lokhttp3/internal/http2/Header;", "ping", "ack", "payload1", "payload2", SentryThread.JsonKeys.PRIORITY, "streamDependency", "weight", "exclusive", "pushPromise", "promisedStreamId", "requestHeaders", "rstStream", "settings", "clearPrevious", "Lokhttp3/internal/http2/Settings;", "windowUpdate", "windowSizeIncrement", "okhttp"}, k = 1, mv = {1, 4, 0})
/* loaded from: classes3.dex */
public interface Handler {
void ackSettings();
void alternateService(int streamId, String origin, ByteString protocol, String host, int port, long maxAge);
void data(boolean inFinished, int streamId, BufferedSource source, int length) throws IOException;
void goAway(int lastGoodStreamId, ErrorCode errorCode, ByteString debugData);
void headers(boolean inFinished, int streamId, int associatedStreamId, List<Header> headerBlock);
void ping(boolean ack, int payload1, int payload2);
void priority(int streamId, int streamDependency, int weight, boolean exclusive);
void pushPromise(int streamId, int promisedStreamId, List<Header> requestHeaders) throws IOException;
void rstStream(int streamId, ErrorCode errorCode);
void settings(boolean clearPrevious, Settings settings);
void windowUpdate(int streamId, long windowSizeIncrement);
}
public Http2Reader(BufferedSource source, boolean z) {
Intrinsics.checkNotNullParameter(source, "source");
this.source = source;
this.client = z;
ContinuationSource continuationSource = new ContinuationSource(source);
this.continuation = continuationSource;
this.hpackReader = new Hpack.Reader(continuationSource, 4096, 0, 4, null);
}
public final void readConnectionPreface(Handler handler) throws IOException {
Intrinsics.checkNotNullParameter(handler, "handler");
if (this.client) {
if (!nextFrame(true, handler)) {
throw new IOException("Required SETTINGS preface not received");
}
return;
}
ByteString readByteString = this.source.readByteString(Http2.CONNECTION_PREFACE.size());
Logger logger2 = logger;
if (logger2.isLoggable(Level.FINE)) {
logger2.fine(Util.format("<< CONNECTION " + readByteString.hex(), new Object[0]));
}
if (!Intrinsics.areEqual(Http2.CONNECTION_PREFACE, readByteString)) {
throw new IOException("Expected a connection header but was " + readByteString.utf8());
}
}
public final boolean nextFrame(boolean requireSettings, Handler handler) throws IOException {
Intrinsics.checkNotNullParameter(handler, "handler");
try {
this.source.require(9L);
int readMedium = Util.readMedium(this.source);
if (readMedium > 16384) {
throw new IOException("FRAME_SIZE_ERROR: " + readMedium);
}
int and = Util.and(this.source.readByte(), 255);
int and2 = Util.and(this.source.readByte(), 255);
int readInt = this.source.readInt() & Integer.MAX_VALUE;
Logger logger2 = logger;
if (logger2.isLoggable(Level.FINE)) {
logger2.fine(Http2.INSTANCE.frameLog(true, readInt, readMedium, and, and2));
}
if (requireSettings && and != 4) {
throw new IOException("Expected a SETTINGS frame but was " + Http2.INSTANCE.formattedType$okhttp(and));
}
switch (and) {
case 0:
readData(handler, readMedium, and2, readInt);
return true;
case 1:
readHeaders(handler, readMedium, and2, readInt);
return true;
case 2:
readPriority(handler, readMedium, and2, readInt);
return true;
case 3:
readRstStream(handler, readMedium, and2, readInt);
return true;
case 4:
readSettings(handler, readMedium, and2, readInt);
return true;
case 5:
readPushPromise(handler, readMedium, and2, readInt);
return true;
case 6:
readPing(handler, readMedium, and2, readInt);
return true;
case 7:
readGoAway(handler, readMedium, and2, readInt);
return true;
case 8:
readWindowUpdate(handler, readMedium, and2, readInt);
return true;
default:
this.source.skip(readMedium);
return true;
}
} catch (EOFException unused) {
return false;
}
}
private final void readHeaders(Handler handler, int length, int flags, int streamId) throws IOException {
if (streamId == 0) {
throw new IOException("PROTOCOL_ERROR: TYPE_HEADERS streamId == 0");
}
boolean z = (flags & 1) != 0;
int and = (flags & 8) != 0 ? Util.and(this.source.readByte(), 255) : 0;
if ((flags & 32) != 0) {
readPriority(handler, streamId);
length -= 5;
}
handler.headers(z, streamId, -1, readHeaderBlock(INSTANCE.lengthWithoutPadding(length, flags, and), and, flags, streamId));
}
private final List<Header> readHeaderBlock(int length, int padding, int flags, int streamId) throws IOException {
this.continuation.setLeft(length);
ContinuationSource continuationSource = this.continuation;
continuationSource.setLength(continuationSource.getLeft());
this.continuation.setPadding(padding);
this.continuation.setFlags(flags);
this.continuation.setStreamId(streamId);
this.hpackReader.readHeaders();
return this.hpackReader.getAndResetHeaderList();
}
private final void readData(Handler handler, int length, int flags, int streamId) throws IOException {
if (streamId == 0) {
throw new IOException("PROTOCOL_ERROR: TYPE_DATA streamId == 0");
}
boolean z = (flags & 1) != 0;
if ((flags & 32) != 0) {
throw new IOException("PROTOCOL_ERROR: FLAG_COMPRESSED without SETTINGS_COMPRESS_DATA");
}
int and = (flags & 8) != 0 ? Util.and(this.source.readByte(), 255) : 0;
handler.data(z, streamId, this.source, INSTANCE.lengthWithoutPadding(length, flags, and));
this.source.skip(and);
}
private final void readPriority(Handler handler, int length, int flags, int streamId) throws IOException {
if (length != 5) {
throw new IOException("TYPE_PRIORITY length: " + length + " != 5");
}
if (streamId == 0) {
throw new IOException("TYPE_PRIORITY streamId == 0");
}
readPriority(handler, streamId);
}
private final void readPriority(Handler handler, int streamId) throws IOException {
int readInt = this.source.readInt();
handler.priority(streamId, readInt & Integer.MAX_VALUE, Util.and(this.source.readByte(), 255) + 1, (((int) 2147483648L) & readInt) != 0);
}
private final void readRstStream(Handler handler, int length, int flags, int streamId) throws IOException {
if (length != 4) {
throw new IOException("TYPE_RST_STREAM length: " + length + " != 4");
}
if (streamId == 0) {
throw new IOException("TYPE_RST_STREAM streamId == 0");
}
int readInt = this.source.readInt();
ErrorCode fromHttp2 = ErrorCode.INSTANCE.fromHttp2(readInt);
if (fromHttp2 == null) {
throw new IOException("TYPE_RST_STREAM unexpected error code: " + readInt);
}
handler.rstStream(streamId, fromHttp2);
}
/* JADX WARN: Code restructure failed: missing block: B:31:0x007e, code lost:
throw new java.io.IOException("PROTOCOL_ERROR SETTINGS_MAX_FRAME_SIZE: " + r4);
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
private final void readSettings(okhttp3.internal.http2.Http2Reader.Handler r8, int r9, int r10, int r11) throws java.io.IOException {
/*
r7 = this;
if (r11 != 0) goto Lc0
r11 = 1
r10 = r10 & r11
if (r10 == 0) goto L16
if (r9 != 0) goto Lc
r8.ackSettings()
return
Lc:
java.io.IOException r7 = new java.io.IOException
java.lang.String r8 = "FRAME_SIZE_ERROR ack frame should be empty!"
r7.<init>(r8)
java.lang.Throwable r7 = (java.lang.Throwable) r7
throw r7
L16:
int r10 = r9 % 6
if (r10 != 0) goto La9
okhttp3.internal.http2.Settings r10 = new okhttp3.internal.http2.Settings
r10.<init>()
r0 = 0
kotlin.ranges.IntRange r9 = kotlin.ranges.RangesKt.until(r0, r9)
kotlin.ranges.IntProgression r9 = (kotlin.ranges.IntProgression) r9
r1 = 6
kotlin.ranges.IntProgression r9 = kotlin.ranges.RangesKt.step(r9, r1)
int r1 = r9.getFirst()
int r2 = r9.getLast()
int r9 = r9.getStep()
if (r9 < 0) goto L3c
if (r1 > r2) goto La5
goto L3e
L3c:
if (r1 < r2) goto La5
L3e:
okio.BufferedSource r3 = r7.source
short r3 = r3.readShort()
r4 = 65535(0xffff, float:9.1834E-41)
int r3 = okhttp3.internal.Util.and(r3, r4)
okio.BufferedSource r4 = r7.source
int r4 = r4.readInt()
r5 = 2
if (r3 == r5) goto L8f
r5 = 3
r6 = 4
if (r3 == r5) goto L8d
if (r3 == r6) goto L7f
r5 = 5
if (r3 == r5) goto L5e
goto L9e
L5e:
r5 = 16384(0x4000, float:2.2959E-41)
if (r4 < r5) goto L68
r5 = 16777215(0xffffff, float:2.3509886E-38)
if (r4 > r5) goto L68
goto L9e
L68:
java.io.IOException r7 = new java.io.IOException
java.lang.StringBuilder r8 = new java.lang.StringBuilder
java.lang.String r9 = "PROTOCOL_ERROR SETTINGS_MAX_FRAME_SIZE: "
r8.<init>(r9)
java.lang.StringBuilder r8 = r8.append(r4)
java.lang.String r8 = r8.toString()
r7.<init>(r8)
java.lang.Throwable r7 = (java.lang.Throwable) r7
throw r7
L7f:
if (r4 < 0) goto L83
r3 = 7
goto L9e
L83:
java.io.IOException r7 = new java.io.IOException
java.lang.String r8 = "PROTOCOL_ERROR SETTINGS_INITIAL_WINDOW_SIZE > 2^31 - 1"
r7.<init>(r8)
java.lang.Throwable r7 = (java.lang.Throwable) r7
throw r7
L8d:
r3 = r6
goto L9e
L8f:
if (r4 == 0) goto L9e
if (r4 != r11) goto L94
goto L9e
L94:
java.io.IOException r7 = new java.io.IOException
java.lang.String r8 = "PROTOCOL_ERROR SETTINGS_ENABLE_PUSH != 0 or 1"
r7.<init>(r8)
java.lang.Throwable r7 = (java.lang.Throwable) r7
throw r7
L9e:
r10.set(r3, r4)
if (r1 == r2) goto La5
int r1 = r1 + r9
goto L3e
La5:
r8.settings(r0, r10)
return
La9:
java.io.IOException r7 = new java.io.IOException
java.lang.StringBuilder r8 = new java.lang.StringBuilder
java.lang.String r10 = "TYPE_SETTINGS length % 6 != 0: "
r8.<init>(r10)
java.lang.StringBuilder r8 = r8.append(r9)
java.lang.String r8 = r8.toString()
r7.<init>(r8)
java.lang.Throwable r7 = (java.lang.Throwable) r7
throw r7
Lc0:
java.io.IOException r7 = new java.io.IOException
java.lang.String r8 = "TYPE_SETTINGS streamId != 0"
r7.<init>(r8)
java.lang.Throwable r7 = (java.lang.Throwable) r7
throw r7
*/
throw new UnsupportedOperationException("Method not decompiled: okhttp3.internal.http2.Http2Reader.readSettings(okhttp3.internal.http2.Http2Reader$Handler, int, int, int):void");
}
private final void readPushPromise(Handler handler, int length, int flags, int streamId) throws IOException {
if (streamId == 0) {
throw new IOException("PROTOCOL_ERROR: TYPE_PUSH_PROMISE streamId == 0");
}
int and = (flags & 8) != 0 ? Util.and(this.source.readByte(), 255) : 0;
handler.pushPromise(streamId, this.source.readInt() & Integer.MAX_VALUE, readHeaderBlock(INSTANCE.lengthWithoutPadding(length - 4, flags, and), and, flags, streamId));
}
private final void readPing(Handler handler, int length, int flags, int streamId) throws IOException {
if (length != 8) {
throw new IOException("TYPE_PING length != 8: " + length);
}
if (streamId != 0) {
throw new IOException("TYPE_PING streamId != 0");
}
handler.ping((flags & 1) != 0, this.source.readInt(), this.source.readInt());
}
private final void readGoAway(Handler handler, int length, int flags, int streamId) throws IOException {
if (length < 8) {
throw new IOException("TYPE_GOAWAY length < 8: " + length);
}
if (streamId != 0) {
throw new IOException("TYPE_GOAWAY streamId != 0");
}
int readInt = this.source.readInt();
int readInt2 = this.source.readInt();
int i = length - 8;
ErrorCode fromHttp2 = ErrorCode.INSTANCE.fromHttp2(readInt2);
if (fromHttp2 == null) {
throw new IOException("TYPE_GOAWAY unexpected error code: " + readInt2);
}
ByteString byteString = ByteString.EMPTY;
if (i > 0) {
byteString = this.source.readByteString(i);
}
handler.goAway(readInt, fromHttp2, byteString);
}
private final void readWindowUpdate(Handler handler, int length, int flags, int streamId) throws IOException {
if (length != 4) {
throw new IOException("TYPE_WINDOW_UPDATE length !=4: " + length);
}
long and = Util.and(this.source.readInt(), 2147483647L);
if (and == 0) {
throw new IOException("windowSizeIncrement was 0");
}
handler.windowUpdate(streamId, and);
}
@Override // java.io.Closeable, java.lang.AutoCloseable
public void close() throws IOException {
this.source.close();
}
/* compiled from: Http2Reader.kt */
@Metadata(bv = {1, 0, 3}, d1 = {"\u00004\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0002\b\u0011\n\u0002\u0010\u0002\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0018\u0002\n\u0000\b\u0000\u0018\u00002\u00020\u0001B\r\u0012\u0006\u0010\u0002\u001a\u00020\u0003¢\u0006\u0002\u0010\u0004J\b\u0010\u0017\u001a\u00020\u0018H\u0016J\u0018\u0010\u0019\u001a\u00020\u001a2\u0006\u0010\u001b\u001a\u00020\u001c2\u0006\u0010\u001d\u001a\u00020\u001aH\u0016J\b\u0010\u001e\u001a\u00020\u0018H\u0002J\b\u0010\u001f\u001a\u00020 H\u0016R\u001a\u0010\u0005\u001a\u00020\u0006X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0007\u0010\b\"\u0004\b\t\u0010\nR\u001a\u0010\u000b\u001a\u00020\u0006X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\f\u0010\b\"\u0004\b\r\u0010\nR\u001a\u0010\u000e\u001a\u00020\u0006X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u000f\u0010\b\"\u0004\b\u0010\u0010\nR\u001a\u0010\u0011\u001a\u00020\u0006X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0012\u0010\b\"\u0004\b\u0013\u0010\nR\u000e\u0010\u0002\u001a\u00020\u0003X\u0082\u0004¢\u0006\u0002\n\u0000R\u001a\u0010\u0014\u001a\u00020\u0006X\u0086\u000e¢\u0006\u000e\n\u0000\u001a\u0004\b\u0015\u0010\b\"\u0004\b\u0016\u0010\\u0006!"}, d2 = {"Lokhttp3/internal/http2/Http2Reader$ContinuationSource;", "Lokio/Source;", TransactionInfo.JsonKeys.SOURCE, "Lokio/BufferedSource;", "(Lokio/BufferedSource;)V", "flags", "", "getFlags", "()I", "setFlags", "(I)V", "left", "getLeft", "setLeft", SentryEnvelopeItemHeader.JsonKeys.LENGTH, "getLength", "setLength", "padding", "getPadding", "setPadding", "streamId", "getStreamId", "setStreamId", "close", "", "read", "", "sink", "Lokio/Buffer;", "byteCount", "readContinuationHeader", ProfilingTraceData.TRUNCATION_REASON_TIMEOUT, "Lokio/Timeout;", "okhttp"}, k = 1, mv = {1, 4, 0})
/* loaded from: classes3.dex */
public static final class ContinuationSource implements Source {
private int flags;
private int left;
private int length;
private int padding;
private final BufferedSource source;
private int streamId;
@Override // okio.Source, java.io.Closeable, java.lang.AutoCloseable
public void close() throws IOException {
}
public final int getFlags() {
return this.flags;
}
public final int getLeft() {
return this.left;
}
public final int getLength() {
return this.length;
}
public final int getPadding() {
return this.padding;
}
public final int getStreamId() {
return this.streamId;
}
public final void setFlags(int i) {
this.flags = i;
}
public final void setLeft(int i) {
this.left = i;
}
public final void setLength(int i) {
this.length = i;
}
public final void setPadding(int i) {
this.padding = i;
}
public final void setStreamId(int i) {
this.streamId = i;
}
public ContinuationSource(BufferedSource source) {
Intrinsics.checkNotNullParameter(source, "source");
this.source = source;
}
@Override // okio.Source
public long read(Buffer sink, long byteCount) throws IOException {
Intrinsics.checkNotNullParameter(sink, "sink");
while (true) {
int i = this.left;
if (i == 0) {
this.source.skip(this.padding);
this.padding = 0;
if ((this.flags & 4) != 0) {
return -1L;
}
readContinuationHeader();
} else {
long read = this.source.read(sink, Math.min(byteCount, i));
if (read == -1) {
return -1L;
}
this.left -= (int) read;
return read;
}
}
}
@Override // okio.Source
/* renamed from: timeout */
public Timeout getTimeout() {
return this.source.getTimeout();
}
private final void readContinuationHeader() throws IOException {
int i = this.streamId;
int readMedium = Util.readMedium(this.source);
this.left = readMedium;
this.length = readMedium;
int and = Util.and(this.source.readByte(), 255);
this.flags = Util.and(this.source.readByte(), 255);
if (Http2Reader.INSTANCE.getLogger().isLoggable(Level.FINE)) {
Http2Reader.INSTANCE.getLogger().fine(Http2.INSTANCE.frameLog(true, this.streamId, this.length, and, this.flags));
}
int readInt = this.source.readInt() & Integer.MAX_VALUE;
this.streamId = readInt;
if (and != 9) {
throw new IOException(and + " != TYPE_CONTINUATION");
}
if (readInt != i) {
throw new IOException("TYPE_CONTINUATION streamId changed");
}
}
}
/* compiled from: Http2Reader.kt */
@Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u001c\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\b\n\u0002\b\u0004\b\u0086\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\u001e\u0010\u0007\u001a\u00020\b2\u0006\u0010\t\u001a\u00020\b2\u0006\u0010\n\u001a\u00020\b2\u0006\u0010\u000b\u001a\u00020\bR\u0011\u0010\u0003\u001a\u00020\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u0005\u0010\u0006¨\u0006\f"}, d2 = {"Lokhttp3/internal/http2/Http2Reader$Companion;", "", "()V", SentryEvent.JsonKeys.LOGGER, "Ljava/util/logging/Logger;", "getLogger", "()Ljava/util/logging/Logger;", "lengthWithoutPadding", "", SentryEnvelopeItemHeader.JsonKeys.LENGTH, "flags", "padding", "okhttp"}, k = 1, mv = {1, 4, 0})
/* loaded from: classes3.dex */
public static final class Companion {
private Companion() {
}
public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
this();
}
public final Logger getLogger() {
return Http2Reader.logger;
}
public final int lengthWithoutPadding(int length, int flags, int padding) throws IOException {
if ((flags & 8) != 0) {
length--;
}
if (padding <= length) {
return length - padding;
}
throw new IOException("PROTOCOL_ERROR padding " + padding + " > remaining length " + length);
}
}
static {
Logger logger2 = Logger.getLogger(Http2.class.getName());
Intrinsics.checkNotNullExpressionValue(logger2, "Logger.getLogger(Http2::class.java.name)");
logger = logger2;
}
}