package okhttp3.repackaged.internal.framed; import com.google.common.primitives.SignedBytes; import com.google.common.primitives.UnsignedBytes; import io.beid.beidk.definitions.LivenessStatus; import io.beid.beidk.definitions.SCBHeader; import io.grpc.internal.GrpcUtil; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import o.C15145giV; import o.C15183gjd; import o.InterfaceC15142giR; import o.giM; import o.giP; import o.giZ; /* JADX INFO: Access modifiers changed from: package-private */ /* loaded from: classes6.dex */ public final class a { private static final int ako = 15; private static final int akp = 31; private static final int akq = 63; private static final int akr = 127; private static final Header[] aks = {new Header(Header.TARGET_AUTHORITY, ""), new Header(Header.TARGET_METHOD, "GET"), new Header(Header.TARGET_METHOD, GrpcUtil.HTTP_METHOD), new Header(Header.TARGET_PATH, "/"), new Header(Header.TARGET_PATH, "/index.html"), new Header(Header.TARGET_SCHEME, "http"), new Header(Header.TARGET_SCHEME, "https"), new Header(Header.RESPONSE_STATUS, "200"), new Header(Header.RESPONSE_STATUS, "204"), new Header(Header.RESPONSE_STATUS, "206"), new Header(Header.RESPONSE_STATUS, "304"), new Header(Header.RESPONSE_STATUS, "400"), new Header(Header.RESPONSE_STATUS, "404"), new Header(Header.RESPONSE_STATUS, LivenessStatus.ERROR_UNKNOW), new Header("accept-charset", ""), new Header(GrpcUtil.CONTENT_ACCEPT_ENCODING, "gzip, deflate"), new Header(SCBHeader.SCB_REQ_HEADER_ACCEPT_LANGUAGE, ""), new Header("accept-ranges", ""), new Header("accept", ""), new Header("access-control-allow-origin", ""), new Header("age", ""), new Header("allow", ""), new Header("authorization", ""), new Header("cache-control", ""), new Header("content-disposition", ""), new Header(GrpcUtil.CONTENT_ENCODING, ""), new Header("content-language", ""), new Header("content-length", ""), new Header("content-location", ""), new Header("content-range", ""), new Header("content-type", ""), new Header("cookie", ""), new Header("date", ""), new Header("etag", ""), new Header("expect", ""), new Header("expires", ""), new Header("from", ""), new Header("host", ""), new Header("if-match", ""), new Header("if-modified-since", ""), new Header("if-none-match", ""), new Header("if-range", ""), new Header("if-unmodified-since", ""), new Header("last-modified", ""), new Header("link", ""), new Header("location", ""), new Header("max-forwards", ""), new Header("proxy-authenticate", ""), new Header("proxy-authorization", ""), new Header("range", ""), new Header("referer", ""), new Header("refresh", ""), new Header("retry-after", ""), new Header("server", ""), new Header("set-cookie", ""), new Header("strict-transport-security", ""), new Header("transfer-encoding", ""), new Header("user-agent", ""), new Header("vary", ""), new Header("via", ""), new Header("www-authenticate", "")}; private static final Map NAME_TO_FIRST_INDEX = uD(); private a() { } /* renamed from: okhttp3.repackaged.internal.framed.a$a, reason: collision with other inner class name */ /* loaded from: classes6.dex */ static final class C0130a { private int headerTableSizeSetting; private int maxDynamicTableByteCount; private final InterfaceC15142giR source; private final List
akt = new ArrayList(); Header[] aku = new Header[8]; int nextHeaderIndex = 7; int headerCount = 0; int dynamicTableByteCount = 0; /* JADX INFO: Access modifiers changed from: package-private */ public C0130a(int i, giZ giz) { this.headerTableSizeSetting = i; this.maxDynamicTableByteCount = i; this.source = C15145giV.a(giz); } /* JADX INFO: Access modifiers changed from: package-private */ public final void x(int i) { this.headerTableSizeSetting = i; this.maxDynamicTableByteCount = i; uG(); } private void uG() { int i = this.maxDynamicTableByteCount; int i2 = this.dynamicTableByteCount; if (i < i2) { if (i == 0) { uH(); } else { y(i2 - i); } } } private void uH() { this.akt.clear(); Arrays.fill(this.aku, (Object) null); this.nextHeaderIndex = this.aku.length - 1; this.headerCount = 0; this.dynamicTableByteCount = 0; } private int y(int i) { int i2; int i3 = 0; if (i > 0) { int length = this.aku.length; while (true) { length--; i2 = this.nextHeaderIndex; if (length < i2 || i <= 0) { break; } i -= this.aku[length].hpackSize; this.dynamicTableByteCount -= this.aku[length].hpackSize; this.headerCount--; i3++; } Header[] headerArr = this.aku; int i4 = i2 + 1; System.arraycopy(headerArr, i4, headerArr, i4 + i3, this.headerCount); this.nextHeaderIndex += i3; } return i3; } /* JADX INFO: Access modifiers changed from: package-private */ public final void readHeaders() throws IOException { while (!this.source.a()) { byte i = this.source.i(); int i2 = i & UnsignedBytes.MAX_VALUE; if (i2 == 128) { throw new IOException("index == 0"); } if ((i & 128) == 128) { z(readInt(i2, 127) - 1); } else if (i2 == 64) { uJ(); } else if ((i & SignedBytes.MAX_POWER_OF_TWO) == 64) { C(readInt(i2, 63) - 1); } else if ((i & 32) == 32) { int readInt = readInt(i2, 31); this.maxDynamicTableByteCount = readInt; if (readInt < 0 || readInt > this.headerTableSizeSetting) { StringBuilder sb = new StringBuilder("Invalid dynamic table size update "); sb.append(this.maxDynamicTableByteCount); throw new IOException(sb.toString()); } uG(); } else if (i2 == 16 || i2 == 0) { uI(); } else { B(readInt(i2, 15) - 1); } } } public final List
getAndResetHeaderList() { ArrayList arrayList = new ArrayList(this.akt); this.akt.clear(); return arrayList; } private void z(int i) throws IOException { if (E(i)) { this.akt.add(a.aks[i]); return; } int A = A(i - a.aks.length); if (A >= 0) { Header[] headerArr = this.aku; if (A <= headerArr.length - 1) { this.akt.add(headerArr[A]); return; } } StringBuilder sb = new StringBuilder("Header index too large "); sb.append(i + 1); throw new IOException(sb.toString()); } private void B(int i) throws IOException { this.akt.add(new Header(D(i), readByteString())); } private void uI() throws IOException { this.akt.add(new Header(a.a(readByteString()), readByteString())); } private void C(int i) throws IOException { a(-1, new Header(D(i), readByteString())); } private void uJ() throws IOException { a(-1, new Header(a.a(readByteString()), readByteString())); } private giP D(int i) { return E(i) ? a.aks[i].name : this.aku[A(i - a.aks.length)].name; } private boolean E(int i) { return i >= 0 && i <= a.aks.length - 1; } private void a(int i, Header header) { this.akt.add(header); int i2 = header.hpackSize; if (i != -1) { i2 -= this.aku[A(i)].hpackSize; } int i3 = this.maxDynamicTableByteCount; if (i2 > i3) { uH(); return; } int y = y((this.dynamicTableByteCount + i2) - i3); if (i == -1) { int i4 = this.headerCount; Header[] headerArr = this.aku; if (i4 + 1 > headerArr.length) { Header[] headerArr2 = new Header[headerArr.length << 1]; System.arraycopy(headerArr, 0, headerArr2, headerArr.length, headerArr.length); this.nextHeaderIndex = this.aku.length - 1; this.aku = headerArr2; } int i5 = this.nextHeaderIndex; this.nextHeaderIndex = i5 - 1; this.aku[i5] = header; this.headerCount++; } else { this.aku[i + A(i) + y] = header; } this.dynamicTableByteCount += i2; } private int uK() throws IOException { return this.source.i() & UnsignedBytes.MAX_VALUE; } final int readInt(int i, int i2) throws IOException { int i3 = i & i2; if (i3 < i2) { return i3; } int i4 = 0; while (true) { int uK = uK(); if ((uK & 128) == 0) { return i2 + (uK << i4); } i2 += (uK & 127) << i4; i4 += 7; } } final giP readByteString() throws IOException { int uK = uK(); boolean z = (uK & 128) == 128; int readInt = readInt(uK, 127); if (z) { return giP.c(okhttp3.repackaged.internal.framed.b.uO().decode(this.source.d(readInt))); } return this.source.e(readInt); } final int maxDynamicTableByteCount() { return this.maxDynamicTableByteCount; } private int A(int i) { return this.nextHeaderIndex + 1 + i; } } private static Map uD() { LinkedHashMap linkedHashMap = new LinkedHashMap(aks.length); int i = 0; while (true) { Header[] headerArr = aks; if (i < headerArr.length) { if (!linkedHashMap.containsKey(headerArr[i].name)) { linkedHashMap.put(headerArr[i].name, Integer.valueOf(i)); } i++; } else { return Collections.unmodifiableMap(linkedHashMap); } } } /* loaded from: classes6.dex */ static final class b { private final giM akv; /* JADX INFO: Access modifiers changed from: package-private */ public b(giM gim) { this.akv = gim; } /* JADX INFO: Access modifiers changed from: package-private */ public final void writeHeaders(List
list) throws IOException { int size = list.size(); for (int i = 0; i < size; i++) { giP c = list.get(i).name.c(); Integer num = (Integer) a.NAME_TO_FIRST_INDEX.get(c); if (num != null) { writeInt(num.intValue() + 1, 15, 0); c(list.get(i).value); } else { this.akv.b(0); c(c); c(list.get(i).value); } } } final void writeInt(int i, int i2, int i3) throws IOException { if (i < i2) { this.akv.b(i | i3); return; } this.akv.b(i3 | i2); int i4 = i - i2; while (i4 >= 128) { this.akv.b(128 | (i4 & 127)); i4 >>>= 7; } this.akv.b(i4); } final void c(giP gip) throws IOException { writeInt(gip.d.length, 127, 0); giM gim = this.akv; if (gip == null) { throw new IllegalArgumentException("byteString == null"); } byte[] bArr = gip.d; gim.a(bArr, 0, bArr.length); } } /* JADX INFO: Access modifiers changed from: private */ public static giP a(giP gip) throws IOException { int length = gip.d.length; for (int i = 0; i < length; i++) { byte b2 = gip.d[i]; if (b2 >= 65 && b2 <= 90) { StringBuilder sb = new StringBuilder("PROTOCOL_ERROR response malformed: mixed case name: "); String str = gip.c; if (str == null) { str = new String(gip.d, C15183gjd.e); gip.c = str; } sb.append(str); throw new IOException(sb.toString()); } } return gip; } }