291 lines
11 KiB
Java
291 lines
11 KiB
Java
package okhttp3.repackaged.internal.http;
|
|
|
|
import java.io.IOException;
|
|
import java.net.ProtocolException;
|
|
import java.util.ArrayList;
|
|
import java.util.LinkedHashSet;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.concurrent.TimeUnit;
|
|
import o.C15145giV;
|
|
import o.C15183gjd;
|
|
import o.giP;
|
|
import o.giS;
|
|
import o.giX;
|
|
import o.giZ;
|
|
import okhttp3.repackaged.Headers;
|
|
import okhttp3.repackaged.Protocol;
|
|
import okhttp3.repackaged.Request;
|
|
import okhttp3.repackaged.Response;
|
|
import okhttp3.repackaged.ResponseBody;
|
|
import okhttp3.repackaged.internal.Util;
|
|
import okhttp3.repackaged.internal.framed.ErrorCode;
|
|
import okhttp3.repackaged.internal.framed.FramedConnection;
|
|
import okhttp3.repackaged.internal.framed.FramedStream;
|
|
import okhttp3.repackaged.internal.framed.Header;
|
|
|
|
/* loaded from: classes6.dex */
|
|
public final class Http2xStream implements HttpStream {
|
|
private static final giP alN;
|
|
private static final giP alO;
|
|
private static final giP alP;
|
|
private static final giP alQ;
|
|
private static final giP alR;
|
|
private static final giP alS;
|
|
private static final giP alT;
|
|
private static final giP alU;
|
|
private static final List<giP> alV;
|
|
private static final List<giP> alW;
|
|
private static final List<giP> alX;
|
|
private static final List<giP> alY;
|
|
private FramedStream alZ;
|
|
private final FramedConnection framedConnection;
|
|
private HttpEngine httpEngine;
|
|
private final StreamAllocation streamAllocation;
|
|
|
|
static {
|
|
giP b = giP.b("connection");
|
|
alN = b;
|
|
giP b2 = giP.b("host");
|
|
alO = b2;
|
|
giP b3 = giP.b("keep-alive");
|
|
alP = b3;
|
|
giP b4 = giP.b("proxy-connection");
|
|
alQ = b4;
|
|
giP b5 = giP.b("transfer-encoding");
|
|
alR = b5;
|
|
giP b6 = giP.b("te");
|
|
alS = b6;
|
|
giP b7 = giP.b("encoding");
|
|
alT = b7;
|
|
giP b8 = giP.b("upgrade");
|
|
alU = b8;
|
|
alV = Util.immutableList(b, b2, b3, b4, b5, Header.TARGET_METHOD, Header.TARGET_PATH, Header.TARGET_SCHEME, Header.TARGET_AUTHORITY, Header.TARGET_HOST, Header.VERSION);
|
|
alW = Util.immutableList(b, b2, b3, b4, b5);
|
|
alX = Util.immutableList(b, b2, b3, b4, b6, b5, b7, b8, Header.TARGET_METHOD, Header.TARGET_PATH, Header.TARGET_SCHEME, Header.TARGET_AUTHORITY, Header.TARGET_HOST, Header.VERSION);
|
|
alY = Util.immutableList(b, b2, b3, b4, b6, b5, b7, b8);
|
|
}
|
|
|
|
public Http2xStream(StreamAllocation streamAllocation, FramedConnection framedConnection) {
|
|
this.streamAllocation = streamAllocation;
|
|
this.framedConnection = framedConnection;
|
|
}
|
|
|
|
@Override // okhttp3.repackaged.internal.http.HttpStream
|
|
public final giX createRequestBody(Request request, long j) throws IOException {
|
|
return this.alZ.getSink();
|
|
}
|
|
|
|
@Override // okhttp3.repackaged.internal.http.HttpStream
|
|
public final void writeRequestHeaders(Request request) throws IOException {
|
|
List<Header> spdy3HeadersList;
|
|
if (this.alZ != null) {
|
|
return;
|
|
}
|
|
this.httpEngine.writingRequestHeaders();
|
|
boolean h = this.httpEngine.h(request);
|
|
if (this.framedConnection.getProtocol() == Protocol.HTTP_2) {
|
|
spdy3HeadersList = http2HeadersList(request);
|
|
} else {
|
|
spdy3HeadersList = spdy3HeadersList(request);
|
|
}
|
|
FramedStream newStream = this.framedConnection.newStream(spdy3HeadersList, h, true);
|
|
this.alZ = newStream;
|
|
newStream.readTimeout().timeout(this.httpEngine.client.readTimeoutMillis(), TimeUnit.MILLISECONDS);
|
|
this.alZ.writeTimeout().timeout(this.httpEngine.client.writeTimeoutMillis(), TimeUnit.MILLISECONDS);
|
|
}
|
|
|
|
@Override // okhttp3.repackaged.internal.http.HttpStream
|
|
public final void writeRequestBody(RetryableSink retryableSink) throws IOException {
|
|
retryableSink.writeToSocket(this.alZ.getSink());
|
|
}
|
|
|
|
@Override // okhttp3.repackaged.internal.http.HttpStream
|
|
public final void finishRequest() throws IOException {
|
|
this.alZ.getSink().close();
|
|
}
|
|
|
|
@Override // okhttp3.repackaged.internal.http.HttpStream
|
|
public final Response.Builder readResponseHeaders() throws IOException {
|
|
if (this.framedConnection.getProtocol() == Protocol.HTTP_2) {
|
|
return readHttp2HeadersList(this.alZ.getResponseHeaders());
|
|
}
|
|
return readSpdy3HeadersList(this.alZ.getResponseHeaders());
|
|
}
|
|
|
|
public static List<Header> spdy3HeadersList(Request request) {
|
|
Headers headers = request.headers();
|
|
ArrayList arrayList = new ArrayList(headers.size() + 5);
|
|
arrayList.add(new Header(Header.TARGET_METHOD, request.method()));
|
|
arrayList.add(new Header(Header.TARGET_PATH, RequestLine.requestPath(request.url())));
|
|
arrayList.add(new Header(Header.VERSION, "HTTP/1.1"));
|
|
arrayList.add(new Header(Header.TARGET_HOST, Util.hostHeader(request.url(), false)));
|
|
arrayList.add(new Header(Header.TARGET_SCHEME, request.url().scheme()));
|
|
LinkedHashSet linkedHashSet = new LinkedHashSet();
|
|
int size = headers.size();
|
|
for (int i = 0; i < size; i++) {
|
|
giP b = giP.b(headers.name(i).toLowerCase(Locale.US));
|
|
if (!alV.contains(b)) {
|
|
String value = headers.value(i);
|
|
if (linkedHashSet.add(b)) {
|
|
arrayList.add(new Header(b, value));
|
|
} else {
|
|
int i2 = 0;
|
|
while (true) {
|
|
if (i2 >= arrayList.size()) {
|
|
break;
|
|
}
|
|
if (((Header) arrayList.get(i2)).name.equals(b)) {
|
|
giP gip = ((Header) arrayList.get(i2)).value;
|
|
String str = gip.c;
|
|
if (str == null) {
|
|
str = new String(gip.d, C15183gjd.e);
|
|
gip.c = str;
|
|
}
|
|
arrayList.set(i2, new Header(b, W(str, value)));
|
|
} else {
|
|
i2++;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
private static String W(String str, String str2) {
|
|
StringBuilder sb = new StringBuilder(str);
|
|
sb.append((char) 0);
|
|
sb.append(str2);
|
|
return sb.toString();
|
|
}
|
|
|
|
public static List<Header> http2HeadersList(Request request) {
|
|
Headers headers = request.headers();
|
|
ArrayList arrayList = new ArrayList(headers.size() + 4);
|
|
arrayList.add(new Header(Header.TARGET_METHOD, request.method()));
|
|
arrayList.add(new Header(Header.TARGET_PATH, RequestLine.requestPath(request.url())));
|
|
arrayList.add(new Header(Header.TARGET_AUTHORITY, Util.hostHeader(request.url(), false)));
|
|
arrayList.add(new Header(Header.TARGET_SCHEME, request.url().scheme()));
|
|
int size = headers.size();
|
|
for (int i = 0; i < size; i++) {
|
|
giP b = giP.b(headers.name(i).toLowerCase(Locale.US));
|
|
if (!alX.contains(b)) {
|
|
arrayList.add(new Header(b, headers.value(i)));
|
|
}
|
|
}
|
|
return arrayList;
|
|
}
|
|
|
|
public static Response.Builder readSpdy3HeadersList(List<Header> list) throws IOException {
|
|
Headers.Builder builder = new Headers.Builder();
|
|
int size = list.size();
|
|
String str = null;
|
|
String str2 = "HTTP/1.1";
|
|
for (int i = 0; i < size; i++) {
|
|
giP gip = list.get(i).name;
|
|
giP gip2 = list.get(i).value;
|
|
String str3 = gip2.c;
|
|
if (str3 == null) {
|
|
str3 = new String(gip2.d, C15183gjd.e);
|
|
gip2.c = str3;
|
|
}
|
|
int i2 = 0;
|
|
while (i2 < str3.length()) {
|
|
int indexOf = str3.indexOf(0, i2);
|
|
if (indexOf == -1) {
|
|
indexOf = str3.length();
|
|
}
|
|
String substring = str3.substring(i2, indexOf);
|
|
if (gip.equals(Header.RESPONSE_STATUS)) {
|
|
str = substring;
|
|
} else if (gip.equals(Header.VERSION)) {
|
|
str2 = substring;
|
|
} else if (!alW.contains(gip)) {
|
|
String str4 = gip.c;
|
|
if (str4 == null) {
|
|
str4 = new String(gip.d, C15183gjd.e);
|
|
gip.c = str4;
|
|
}
|
|
builder.add(str4, substring);
|
|
}
|
|
i2 = indexOf + 1;
|
|
}
|
|
}
|
|
if (str == null) {
|
|
throw new ProtocolException("Expected ':status' header not present");
|
|
}
|
|
StringBuilder sb = new StringBuilder();
|
|
sb.append(str2);
|
|
sb.append(" ");
|
|
sb.append(str);
|
|
StatusLine parse = StatusLine.parse(sb.toString());
|
|
return new Response.Builder().protocol(Protocol.SPDY_3).code(parse.code).message(parse.message).headers(builder.build());
|
|
}
|
|
|
|
public static Response.Builder readHttp2HeadersList(List<Header> list) throws IOException {
|
|
Headers.Builder builder = new Headers.Builder();
|
|
int size = list.size();
|
|
String str = null;
|
|
for (int i = 0; i < size; i++) {
|
|
giP gip = list.get(i).name;
|
|
giP gip2 = list.get(i).value;
|
|
String str2 = gip2.c;
|
|
if (str2 == null) {
|
|
str2 = new String(gip2.d, C15183gjd.e);
|
|
gip2.c = str2;
|
|
}
|
|
if (gip.equals(Header.RESPONSE_STATUS)) {
|
|
str = str2;
|
|
} else if (!alY.contains(gip)) {
|
|
String str3 = gip.c;
|
|
if (str3 == null) {
|
|
str3 = new String(gip.d, C15183gjd.e);
|
|
gip.c = str3;
|
|
}
|
|
builder.add(str3, str2);
|
|
}
|
|
}
|
|
if (str == null) {
|
|
throw new ProtocolException("Expected ':status' header not present");
|
|
}
|
|
StatusLine parse = StatusLine.parse("HTTP/1.1 ".concat(String.valueOf(str)));
|
|
return new Response.Builder().protocol(Protocol.HTTP_2).code(parse.code).message(parse.message).headers(builder.build());
|
|
}
|
|
|
|
@Override // okhttp3.repackaged.internal.http.HttpStream
|
|
public final ResponseBody openResponseBody(Response response) throws IOException {
|
|
return new RealResponseBody(response.headers(), C15145giV.a(new a(this, this.alZ.getSource())));
|
|
}
|
|
|
|
@Override // okhttp3.repackaged.internal.http.HttpStream
|
|
public final void cancel() {
|
|
FramedStream framedStream = this.alZ;
|
|
if (framedStream != null) {
|
|
framedStream.closeLater(ErrorCode.CANCEL);
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes6.dex */
|
|
class a extends giS {
|
|
final Http2xStream ama;
|
|
|
|
/* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
|
|
public a(Http2xStream http2xStream, giZ giz) {
|
|
super(giz);
|
|
this.ama = http2xStream;
|
|
}
|
|
|
|
@Override // o.giS, o.giZ, java.io.Closeable, java.lang.AutoCloseable
|
|
public void close() throws IOException {
|
|
this.ama.streamAllocation.streamFinished(false, this.ama);
|
|
super.close();
|
|
}
|
|
}
|
|
|
|
@Override // okhttp3.repackaged.internal.http.HttpStream
|
|
public final void setHttpEngine(HttpEngine httpEngine) {
|
|
this.httpEngine = httpEngine;
|
|
}
|
|
}
|