what-the-bank/sources/okhttp3/repackaged/internal/framed/Spdy3.java

439 lines
19 KiB
Java

package okhttp3.repackaged.internal.framed;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.ProtocolException;
import java.util.List;
import java.util.zip.Deflater;
import o.C15145giV;
import o.InterfaceC15142giR;
import o.giM;
import o.giN;
import o.giO;
import o.giP;
import o.giX;
import okhttp3.repackaged.Protocol;
import okhttp3.repackaged.internal.Util;
import okhttp3.repackaged.internal.framed.FrameReader;
/* loaded from: classes6.dex */
public final class Spdy3 implements Variant {
static final int agA = 3;
static final int alc = 0;
static final int ald = 1;
static final int ale = 2;
static final int alf = 3;
static final int alg = 4;
static final int alh = 6;
static final int ali = 7;
static final int alj = 8;
static final int alk = 9;
static final int all = 1;
static final int alm = 2;
static final byte[] aln;
@Override // okhttp3.repackaged.internal.framed.Variant
public final Protocol getProtocol() {
return Protocol.SPDY_3;
}
static {
try {
aln = "\u0000\u0000\u0000\u0007options\u0000\u0000\u0000\u0004head\u0000\u0000\u0000\u0004post\u0000\u0000\u0000\u0003put\u0000\u0000\u0000\u0006delete\u0000\u0000\u0000\u0005trace\u0000\u0000\u0000\u0006accept\u0000\u0000\u0000\u000eaccept-charset\u0000\u0000\u0000\u000faccept-encoding\u0000\u0000\u0000\u000faccept-language\u0000\u0000\u0000\raccept-ranges\u0000\u0000\u0000\u0003age\u0000\u0000\u0000\u0005allow\u0000\u0000\u0000\rauthorization\u0000\u0000\u0000\rcache-control\u0000\u0000\u0000\nconnection\u0000\u0000\u0000\fcontent-base\u0000\u0000\u0000\u0010content-encoding\u0000\u0000\u0000\u0010content-language\u0000\u0000\u0000\u000econtent-length\u0000\u0000\u0000\u0010content-location\u0000\u0000\u0000\u000bcontent-md5\u0000\u0000\u0000\rcontent-range\u0000\u0000\u0000\fcontent-type\u0000\u0000\u0000\u0004date\u0000\u0000\u0000\u0004etag\u0000\u0000\u0000\u0006expect\u0000\u0000\u0000\u0007expires\u0000\u0000\u0000\u0004from\u0000\u0000\u0000\u0004host\u0000\u0000\u0000\bif-match\u0000\u0000\u0000\u0011if-modified-since\u0000\u0000\u0000\rif-none-match\u0000\u0000\u0000\bif-range\u0000\u0000\u0000\u0013if-unmodified-since\u0000\u0000\u0000\rlast-modified\u0000\u0000\u0000\blocation\u0000\u0000\u0000\fmax-forwards\u0000\u0000\u0000\u0006pragma\u0000\u0000\u0000\u0012proxy-authenticate\u0000\u0000\u0000\u0013proxy-authorization\u0000\u0000\u0000\u0005range\u0000\u0000\u0000\u0007referer\u0000\u0000\u0000\u000bretry-after\u0000\u0000\u0000\u0006server\u0000\u0000\u0000\u0002te\u0000\u0000\u0000\u0007trailer\u0000\u0000\u0000\u0011transfer-encoding\u0000\u0000\u0000\u0007upgrade\u0000\u0000\u0000\nuser-agent\u0000\u0000\u0000\u0004vary\u0000\u0000\u0000\u0003via\u0000\u0000\u0000\u0007warning\u0000\u0000\u0000\u0010www-authenticate\u0000\u0000\u0000\u0006method\u0000\u0000\u0000\u0003get\u0000\u0000\u0000\u0006status\u0000\u0000\u0000\u0006200 OK\u0000\u0000\u0000\u0007version\u0000\u0000\u0000\bHTTP/1.1\u0000\u0000\u0000\u0003url\u0000\u0000\u0000\u0006public\u0000\u0000\u0000\nset-cookie\u0000\u0000\u0000\nkeep-alive\u0000\u0000\u0000\u0006origin100101201202205206300302303304305306307402405406407408409410411412413414415416417502504505203 Non-Authoritative Information204 No Content301 Moved Permanently400 Bad Request401 Unauthorized403 Forbidden404 Not Found500 Internal Server Error501 Not Implemented503 Service UnavailableJan Feb Mar Apr May Jun Jul Aug Sept Oct Nov Dec 00:00:00 Mon, Tue, Wed, Thu, Fri, Sat, Sun, GMTchunked,text/html,image/png,image/jpg,image/gif,application/xml,application/xhtml+xml,text/plain,text/javascript,publicprivatemax-age=gzip,deflate,sdchcharset=utf-8charset=iso-8859-1,utf-,*,enq=0.".getBytes(Util.UTF_8.name());
} catch (UnsupportedEncodingException unused) {
throw new AssertionError();
}
}
@Override // okhttp3.repackaged.internal.framed.Variant
public final FrameReader newReader(InterfaceC15142giR interfaceC15142giR, boolean z) {
return new a(interfaceC15142giR, z);
}
@Override // okhttp3.repackaged.internal.framed.Variant
public final FrameWriter newWriter(giO gio, boolean z) {
return new b(gio, z);
}
/* loaded from: classes6.dex */
static final class a implements FrameReader {
private final c alo;
private final boolean client;
private final InterfaceC15142giR source;
@Override // okhttp3.repackaged.internal.framed.FrameReader
public final void readConnectionPreface() {
}
a(InterfaceC15142giR interfaceC15142giR, boolean z) {
this.source = interfaceC15142giR;
this.alo = new c(interfaceC15142giR);
this.client = z;
}
@Override // okhttp3.repackaged.internal.framed.FrameReader
public final boolean nextFrame(FrameReader.Handler handler) throws IOException {
try {
int k = this.source.k();
int k2 = this.source.k();
int i = ((-16777216) & k2) >>> 24;
int i2 = k2 & 16777215;
if (!((Integer.MIN_VALUE & k) != 0)) {
handler.data((i & 1) != 0, k & Integer.MAX_VALUE, this.source, i2);
return true;
}
int i3 = (2147418112 & k) >>> 16;
if (i3 != 3) {
throw new ProtocolException("version != 3: ".concat(String.valueOf(i3)));
}
switch (65535 & k) {
case 1:
a(handler, i, i2);
return true;
case 2:
b(handler, i, i2);
return true;
case 3:
c(handler, i, i2);
return true;
case 4:
h(handler, i, i2);
return true;
case 5:
default:
this.source.f(i2);
return true;
case 6:
f(handler, i, i2);
return true;
case 7:
g(handler, i, i2);
return true;
case 8:
d(handler, i, i2);
return true;
case 9:
e(handler, i, i2);
return true;
}
} catch (IOException unused) {
return false;
}
}
private void a(FrameReader.Handler handler, int i, int i2) throws IOException {
int k = this.source.k();
int k2 = this.source.k();
this.source.o();
handler.headers((i & 2) != 0, (i & 1) != 0, k & Integer.MAX_VALUE, k2 & Integer.MAX_VALUE, this.alo.F(i2 - 10), HeadersMode.SPDY_SYN_STREAM);
}
private void b(FrameReader.Handler handler, int i, int i2) throws IOException {
handler.headers(false, (i & 1) != 0, this.source.k() & Integer.MAX_VALUE, -1, this.alo.F(i2 - 4), HeadersMode.SPDY_REPLY);
}
private void c(FrameReader.Handler handler, int i, int i2) throws IOException {
if (i2 != 8) {
throw ioException("TYPE_RST_STREAM length: %d != 8", Integer.valueOf(i2));
}
int k = this.source.k();
int k2 = this.source.k();
ErrorCode fromSpdy3Rst = ErrorCode.fromSpdy3Rst(k2);
if (fromSpdy3Rst == null) {
throw ioException("TYPE_RST_STREAM unexpected error code: %d", Integer.valueOf(k2));
}
handler.rstStream(k & Integer.MAX_VALUE, fromSpdy3Rst);
}
private void d(FrameReader.Handler handler, int i, int i2) throws IOException {
handler.headers(false, false, this.source.k() & Integer.MAX_VALUE, -1, this.alo.F(i2 - 4), HeadersMode.SPDY_HEADERS);
}
private void e(FrameReader.Handler handler, int i, int i2) throws IOException {
if (i2 != 8) {
throw ioException("TYPE_WINDOW_UPDATE length: %d != 8", Integer.valueOf(i2));
}
int k = this.source.k();
long k2 = this.source.k() & Integer.MAX_VALUE;
if (k2 == 0) {
throw ioException("windowSizeIncrement was 0", Long.valueOf(k2));
}
handler.windowUpdate(k & Integer.MAX_VALUE, k2);
}
private void f(FrameReader.Handler handler, int i, int i2) throws IOException {
if (i2 != 4) {
throw ioException("TYPE_PING length: %d != 4", Integer.valueOf(i2));
}
int k = this.source.k();
handler.ping(this.client == ((k & 1) == 1), k, 0);
}
private void g(FrameReader.Handler handler, int i, int i2) throws IOException {
if (i2 != 8) {
throw ioException("TYPE_GOAWAY length: %d != 8", Integer.valueOf(i2));
}
int k = this.source.k();
int k2 = this.source.k();
ErrorCode fromSpdyGoAway = ErrorCode.fromSpdyGoAway(k2);
if (fromSpdyGoAway == null) {
throw ioException("TYPE_GOAWAY unexpected error code: %d", Integer.valueOf(k2));
}
handler.goAway(k & Integer.MAX_VALUE, fromSpdyGoAway, giP.a);
}
private void h(FrameReader.Handler handler, int i, int i2) throws IOException {
int k = this.source.k();
if (i2 != (k << 3) + 4) {
throw ioException("TYPE_SETTINGS length: %d != 4 + 8 * %d", Integer.valueOf(i2), Integer.valueOf(k));
}
Settings settings = new Settings();
for (int i3 = 0; i3 < k; i3++) {
int k2 = this.source.k();
settings.d(16777215 & k2, (k2 & (-16777216)) >>> 24, this.source.k());
}
handler.settings((i & 1) != 0, settings);
}
private static IOException ioException(String str, Object... objArr) throws IOException {
throw new IOException(String.format(str, objArr));
}
@Override // java.io.Closeable, java.lang.AutoCloseable
public final void close() throws IOException {
this.alo.close();
}
}
/* loaded from: classes6.dex */
static final class b implements FrameWriter {
private final giM alp;
private final giO alq;
private final boolean client;
private boolean closed;
private final giO sink;
@Override // okhttp3.repackaged.internal.framed.FrameWriter
public final void ackSettings(Settings settings) {
}
@Override // okhttp3.repackaged.internal.framed.FrameWriter
public final int maxDataLength() {
return 16383;
}
@Override // okhttp3.repackaged.internal.framed.FrameWriter
public final void pushPromise(int i, int i2, List<Header> list) throws IOException {
}
b(giO gio, boolean z) {
this.sink = gio;
this.client = z;
Deflater deflater = new Deflater();
deflater.setDictionary(Spdy3.aln);
giM gim = new giM();
this.alp = gim;
this.alq = C15145giV.e(new giN((giX) gim, deflater));
}
@Override // okhttp3.repackaged.internal.framed.FrameWriter
public final void connectionPreface() {
synchronized (this) {
}
}
@Override // okhttp3.repackaged.internal.framed.FrameWriter
public final void flush() throws IOException {
synchronized (this) {
if (this.closed) {
throw new IOException("closed");
}
this.sink.flush();
}
}
@Override // okhttp3.repackaged.internal.framed.FrameWriter
public final void synStream(boolean z, boolean z2, int i, int i2, List<Header> list) throws IOException {
synchronized (this) {
if (this.closed) {
throw new IOException("closed");
}
x(list);
int i3 = (int) (this.alp.a + 10);
int i4 = z2 ? 2 : 0;
this.sink.d(-2147287039);
this.sink.d(((((z ? 1 : 0) | i4) & 255) << 24) | (16777215 & i3));
this.sink.d(i & Integer.MAX_VALUE);
this.sink.d(Integer.MAX_VALUE & i2);
this.sink.g(0);
this.sink.d(this.alp);
this.sink.flush();
}
}
@Override // okhttp3.repackaged.internal.framed.FrameWriter
public final void synReply(boolean z, int i, List<Header> list) throws IOException {
synchronized (this) {
if (this.closed) {
throw new IOException("closed");
}
x(list);
int i2 = (int) (this.alp.a + 4);
this.sink.d(-2147287038);
this.sink.d((((z ? 1 : 0) & 255) << 24) | (i2 & 16777215));
this.sink.d(i & Integer.MAX_VALUE);
this.sink.d(this.alp);
this.sink.flush();
}
}
@Override // okhttp3.repackaged.internal.framed.FrameWriter
public final void headers(int i, List<Header> list) throws IOException {
synchronized (this) {
if (this.closed) {
throw new IOException("closed");
}
x(list);
int i2 = (int) (this.alp.a + 4);
this.sink.d(-2147287032);
this.sink.d(i2 & 16777215);
this.sink.d(i & Integer.MAX_VALUE);
this.sink.d(this.alp);
}
}
@Override // okhttp3.repackaged.internal.framed.FrameWriter
public final void rstStream(int i, ErrorCode errorCode) throws IOException {
synchronized (this) {
if (this.closed) {
throw new IOException("closed");
}
if (errorCode.spdyRstCode == -1) {
throw new IllegalArgumentException();
}
this.sink.d(-2147287037);
this.sink.d(8);
this.sink.d(i & Integer.MAX_VALUE);
this.sink.d(errorCode.spdyRstCode);
this.sink.flush();
}
}
@Override // okhttp3.repackaged.internal.framed.FrameWriter
public final void data(boolean z, int i, giM gim, int i2) throws IOException {
synchronized (this) {
a(i, z ? 1 : 0, gim, i2);
}
}
final void a(int i, int i2, giM gim, int i3) throws IOException {
if (this.closed) {
throw new IOException("closed");
}
long j = i3;
if (j > 16777215) {
throw new IllegalArgumentException("FRAME_TOO_LARGE max size is 16Mib: ".concat(String.valueOf(i3)));
}
this.sink.d(i & Integer.MAX_VALUE);
this.sink.d(((i2 & 255) << 24) | (16777215 & i3));
if (i3 > 0) {
this.sink.write(gim, j);
}
}
private void x(List<Header> list) throws IOException {
this.alq.d(list.size());
int size = list.size();
for (int i = 0; i < size; i++) {
giP gip = list.get(i).name;
this.alq.d(gip.d.length);
this.alq.e(gip);
giP gip2 = list.get(i).value;
this.alq.d(gip2.d.length);
this.alq.e(gip2);
}
this.alq.flush();
}
@Override // okhttp3.repackaged.internal.framed.FrameWriter
public final void settings(Settings settings) throws IOException {
synchronized (this) {
if (this.closed) {
throw new IOException("closed");
}
int size = settings.size();
this.sink.d(-2147287036);
this.sink.d(((size << 3) + 4) & 16777215);
this.sink.d(size);
for (int i = 0; i <= 10; i++) {
if (settings.isSet(i)) {
this.sink.d(((settings.G(i) & 255) << 24) | (i & 16777215));
this.sink.d(settings.get(i));
}
}
this.sink.flush();
}
}
@Override // okhttp3.repackaged.internal.framed.FrameWriter
public final void ping(boolean z, int i, int i2) throws IOException {
synchronized (this) {
if (this.closed) {
throw new IOException("closed");
}
if (z != (this.client != ((i & 1) == 1))) {
throw new IllegalArgumentException("payload != reply");
}
this.sink.d(-2147287034);
this.sink.d(4);
this.sink.d(i);
this.sink.flush();
}
}
@Override // okhttp3.repackaged.internal.framed.FrameWriter
public final void goAway(int i, ErrorCode errorCode, byte[] bArr) throws IOException {
synchronized (this) {
if (this.closed) {
throw new IOException("closed");
}
if (errorCode.spdyGoAwayCode == -1) {
throw new IllegalArgumentException("errorCode.spdyGoAwayCode == -1");
}
this.sink.d(-2147287033);
this.sink.d(8);
this.sink.d(i);
this.sink.d(errorCode.spdyGoAwayCode);
this.sink.flush();
}
}
@Override // okhttp3.repackaged.internal.framed.FrameWriter
public final void windowUpdate(int i, long j) throws IOException {
synchronized (this) {
if (this.closed) {
throw new IOException("closed");
}
if (j == 0 || j > 2147483647L) {
StringBuilder sb = new StringBuilder("windowSizeIncrement must be between 1 and 0x7fffffff: ");
sb.append(j);
throw new IllegalArgumentException(sb.toString());
}
this.sink.d(-2147287031);
this.sink.d(8);
this.sink.d(i);
this.sink.d((int) j);
this.sink.flush();
}
}
@Override // java.io.Closeable, java.lang.AutoCloseable
public final void close() throws IOException {
synchronized (this) {
this.closed = true;
Util.closeAll(this.sink, this.alq);
}
}
}
}