what-the-bank/sources/okhttp3/repackaged/internal/http/OkHeaders.java

159 lines
5.7 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package okhttp3.repackaged.internal.http;
import com.google.common.net.HttpHeaders;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import okhttp3.repackaged.Challenge;
import okhttp3.repackaged.Headers;
import okhttp3.repackaged.Request;
import okhttp3.repackaged.Response;
import okhttp3.repackaged.internal.Platform;
import okhttp3.repackaged.internal.Util;
/* loaded from: classes6.dex */
public final class OkHeaders {
static final String PREFIX;
public static final String RECEIVED_MILLIS;
public static final String RESPONSE_SOURCE;
public static final String SELECTED_PROTOCOL;
public static final String SENT_MILLIS;
static {
String prefix = Platform.get().getPrefix();
PREFIX = prefix;
StringBuilder sb = new StringBuilder();
sb.append(prefix);
sb.append("-Sent-Millis");
SENT_MILLIS = sb.toString();
StringBuilder sb2 = new StringBuilder();
sb2.append(prefix);
sb2.append("-Received-Millis");
RECEIVED_MILLIS = sb2.toString();
StringBuilder sb3 = new StringBuilder();
sb3.append(prefix);
sb3.append("-Selected-Protocol");
SELECTED_PROTOCOL = sb3.toString();
StringBuilder sb4 = new StringBuilder();
sb4.append(prefix);
sb4.append("-Response-Source");
RESPONSE_SOURCE = sb4.toString();
}
private OkHeaders() {
}
public static long contentLength(Request request) {
return contentLength(request.headers());
}
public static long contentLength(Response response) {
return contentLength(response.headers());
}
public static long contentLength(Headers headers) {
return bb(headers.get(HttpHeaders.CONTENT_LENGTH));
}
private static long bb(String str) {
if (str == null) {
return -1L;
}
try {
return Long.parseLong(str);
} catch (NumberFormatException unused) {
return -1L;
}
}
public static boolean varyMatches(Response response, Headers headers, Request request) {
for (String str : o(response)) {
if (!Util.equal(headers.values(str), request.headers(str))) {
return false;
}
}
return true;
}
public static boolean hasVaryAll(Response response) {
return hasVaryAll(response.headers());
}
public static boolean hasVaryAll(Headers headers) {
return varyFields(headers).contains("*");
}
private static Set<String> o(Response response) {
return varyFields(response.headers());
}
public static Set<String> varyFields(Headers headers) {
Set<String> emptySet = Collections.emptySet();
int size = headers.size();
for (int i = 0; i < size; i++) {
if (HttpHeaders.VARY.equalsIgnoreCase(headers.name(i))) {
String value = headers.value(i);
if (emptySet.isEmpty()) {
emptySet = new TreeSet<>((Comparator<? super String>) String.CASE_INSENSITIVE_ORDER);
}
for (String str : value.split(",")) {
emptySet.add(str.trim());
}
}
}
return emptySet;
}
public static Headers varyHeaders(Response response) {
return varyHeaders(response.networkResponse().request().headers(), response.headers());
}
public static Headers varyHeaders(Headers headers, Headers headers2) {
Set<String> varyFields = varyFields(headers2);
if (varyFields.isEmpty()) {
return new Headers.Builder().build();
}
Headers.Builder builder = new Headers.Builder();
int size = headers.size();
for (int i = 0; i < size; i++) {
String name = headers.name(i);
if (varyFields.contains(name)) {
builder.add(name, headers.value(i));
}
}
return builder.build();
}
/* JADX INFO: Access modifiers changed from: package-private */
public static boolean isEndToEnd(String str) {
return (HttpHeaders.CONNECTION.equalsIgnoreCase(str) || "Keep-Alive".equalsIgnoreCase(str) || HttpHeaders.PROXY_AUTHENTICATE.equalsIgnoreCase(str) || HttpHeaders.PROXY_AUTHORIZATION.equalsIgnoreCase(str) || HttpHeaders.TE.equalsIgnoreCase(str) || "Trailers".equalsIgnoreCase(str) || HttpHeaders.TRANSFER_ENCODING.equalsIgnoreCase(str) || HttpHeaders.UPGRADE.equalsIgnoreCase(str)) ? false : true;
}
public static List<Challenge> parseChallenges(Headers headers, String str) {
ArrayList arrayList = new ArrayList();
int size = headers.size();
for (int i = 0; i < size; i++) {
if (str.equalsIgnoreCase(headers.name(i))) {
String value = headers.value(i);
int i2 = 0;
while (i2 < value.length()) {
int skipUntil = HeaderParser.skipUntil(value, i2, " ");
String trim = value.substring(i2, skipUntil).trim();
int skipWhitespace = HeaderParser.skipWhitespace(value, skipUntil);
if (value.regionMatches(true, skipWhitespace, "realm=\"", 0, 7)) {
int i3 = skipWhitespace + 7;
int skipUntil2 = HeaderParser.skipUntil(value, i3, "\"");
String substring = value.substring(i3, skipUntil2);
i2 = HeaderParser.skipWhitespace(value, HeaderParser.skipUntil(value, skipUntil2 + 1, ",") + 1);
arrayList.add(new Challenge(trim, substring));
}
}
}
}
return arrayList;
}
}