what-the-bank/sources/okhttp3/internal/http/BridgeInterceptor.java

100 lines
4.3 KiB
Java

package okhttp3.internal.http;
import java.io.IOException;
import java.util.List;
import o.C14957gcv;
import o.C15157gil;
import o.C15160gio;
import o.gdZ;
import okhttp3.Cookie;
import okhttp3.CookieJar;
import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;
import okhttp3.internal.Util;
/* loaded from: classes.dex */
public final class BridgeInterceptor implements Interceptor {
private final CookieJar cookieJar;
public BridgeInterceptor(CookieJar cookieJar) {
C14957gcv.e(cookieJar, "");
this.cookieJar = cookieJar;
}
@Override // okhttp3.Interceptor
public final Response intercept(Interceptor.Chain chain) throws IOException {
ResponseBody body;
C14957gcv.e(chain, "");
Request request = chain.request();
Request.Builder newBuilder = request.newBuilder();
RequestBody body2 = request.body();
if (body2 != null) {
MediaType contentType = body2.contentType();
if (contentType != null) {
newBuilder.header(com.google.common.net.HttpHeaders.CONTENT_TYPE, contentType.toString());
}
long contentLength = body2.contentLength();
if (contentLength != -1) {
newBuilder.header(com.google.common.net.HttpHeaders.CONTENT_LENGTH, String.valueOf(contentLength));
newBuilder.removeHeader(com.google.common.net.HttpHeaders.TRANSFER_ENCODING);
} else {
newBuilder.header(com.google.common.net.HttpHeaders.TRANSFER_ENCODING, "chunked");
newBuilder.removeHeader(com.google.common.net.HttpHeaders.CONTENT_LENGTH);
}
}
boolean z = false;
if (request.header(com.google.common.net.HttpHeaders.HOST) == null) {
newBuilder.header(com.google.common.net.HttpHeaders.HOST, Util.toHostHeader$default(request.url(), false, 1, null));
}
if (request.header(com.google.common.net.HttpHeaders.CONNECTION) == null) {
newBuilder.header(com.google.common.net.HttpHeaders.CONNECTION, "Keep-Alive");
}
if (request.header(com.google.common.net.HttpHeaders.ACCEPT_ENCODING) == null && request.header(com.google.common.net.HttpHeaders.RANGE) == null) {
newBuilder.header(com.google.common.net.HttpHeaders.ACCEPT_ENCODING, "gzip");
z = true;
}
List<Cookie> loadForRequest = this.cookieJar.loadForRequest(request.url());
if (!loadForRequest.isEmpty()) {
newBuilder.header(com.google.common.net.HttpHeaders.COOKIE, cookieHeader(loadForRequest));
}
if (request.header("User-Agent") == null) {
newBuilder.header("User-Agent", Util.userAgent);
}
Response proceed = chain.proceed(newBuilder.build());
HttpHeaders.receiveHeaders(this.cookieJar, request.url(), proceed.headers());
Response.Builder request2 = proceed.newBuilder().request(request);
if (z && gdZ.a("gzip", Response.header$default(proceed, com.google.common.net.HttpHeaders.CONTENT_ENCODING, null, 2, null), true) && HttpHeaders.promisesBody(proceed) && (body = proceed.body()) != null) {
C15157gil c15157gil = new C15157gil(body.source());
request2.headers(proceed.headers().newBuilder().removeAll(com.google.common.net.HttpHeaders.CONTENT_ENCODING).removeAll(com.google.common.net.HttpHeaders.CONTENT_LENGTH).build());
request2.body(new RealResponseBody(Response.header$default(proceed, com.google.common.net.HttpHeaders.CONTENT_TYPE, null, 2, null), -1L, C15160gio.c(c15157gil)));
}
return request2.build();
}
private final String cookieHeader(List<Cookie> list) {
StringBuilder sb = new StringBuilder();
int i = 0;
for (Object obj : list) {
if (i >= 0) {
Cookie cookie = (Cookie) obj;
if (i > 0) {
sb.append("; ");
}
sb.append(cookie.name());
sb.append('=');
sb.append(cookie.value());
i++;
} else {
throw new ArithmeticException("Index overflow has happened.");
}
}
String obj2 = sb.toString();
C14957gcv.c((Object) obj2, "");
return obj2;
}
}