469 lines
16 KiB
Java
469 lines
16 KiB
Java
package okhttp3;
|
|
|
|
import java.time.Instant;
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.Collections;
|
|
import java.util.Comparator;
|
|
import java.util.Date;
|
|
import java.util.Iterator;
|
|
import java.util.List;
|
|
import java.util.Locale;
|
|
import java.util.Map;
|
|
import java.util.Set;
|
|
import java.util.TreeMap;
|
|
import java.util.TreeSet;
|
|
import o.C13396fZU;
|
|
import o.C14851gaI;
|
|
import o.C14947gcl;
|
|
import o.C14953gcr;
|
|
import o.C14957gcv;
|
|
import o.InterfaceC14932gcO;
|
|
import o.gbB;
|
|
import o.gcH;
|
|
import o.gdZ;
|
|
import okhttp3.internal.Util;
|
|
import okhttp3.internal.http.DatesKt;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class Headers implements Iterable<C13396fZU<? extends String, ? extends String>>, InterfaceC14932gcO {
|
|
public static final Companion Companion = new Companion(null);
|
|
private final String[] namesAndValues;
|
|
|
|
private Headers(String[] strArr) {
|
|
this.namesAndValues = strArr;
|
|
}
|
|
|
|
public final String get(String str) {
|
|
C14957gcv.e(str, "");
|
|
return Companion.get(this.namesAndValues, str);
|
|
}
|
|
|
|
public final Date getDate(String str) {
|
|
C14957gcv.e(str, "");
|
|
String str2 = get(str);
|
|
if (str2 == null) {
|
|
return null;
|
|
}
|
|
return DatesKt.toHttpDateOrNull(str2);
|
|
}
|
|
|
|
public final Instant getInstant(String str) {
|
|
C14957gcv.e(str, "");
|
|
Date date = getDate(str);
|
|
if (date == null) {
|
|
return null;
|
|
}
|
|
return date.toInstant();
|
|
}
|
|
|
|
public final int size() {
|
|
return this.namesAndValues.length / 2;
|
|
}
|
|
|
|
/* renamed from: -deprecated_size, reason: not valid java name */
|
|
public final int m405deprecated_size() {
|
|
return size();
|
|
}
|
|
|
|
public final String name(int i) {
|
|
return this.namesAndValues[i << 1];
|
|
}
|
|
|
|
public final String value(int i) {
|
|
return this.namesAndValues[(i << 1) + 1];
|
|
}
|
|
|
|
public final Set<String> names() {
|
|
C14957gcv.e(gcH.d, "");
|
|
Comparator comparator = String.CASE_INSENSITIVE_ORDER;
|
|
C14957gcv.c(comparator, "");
|
|
TreeSet treeSet = new TreeSet(comparator);
|
|
int size = size();
|
|
for (int i = 0; i < size; i++) {
|
|
treeSet.add(name(i));
|
|
}
|
|
Set<String> unmodifiableSet = Collections.unmodifiableSet(treeSet);
|
|
C14957gcv.c(unmodifiableSet, "");
|
|
return unmodifiableSet;
|
|
}
|
|
|
|
public final List<String> values(String str) {
|
|
C14957gcv.e(str, "");
|
|
int size = size();
|
|
ArrayList arrayList = null;
|
|
for (int i = 0; i < size; i++) {
|
|
if (gdZ.a(str, name(i), true)) {
|
|
if (arrayList == null) {
|
|
arrayList = new ArrayList(2);
|
|
}
|
|
arrayList.add(value(i));
|
|
}
|
|
}
|
|
if (arrayList != null) {
|
|
List<String> unmodifiableList = Collections.unmodifiableList(arrayList);
|
|
C14957gcv.c(unmodifiableList, "");
|
|
return unmodifiableList;
|
|
}
|
|
return C14851gaI.c;
|
|
}
|
|
|
|
public final long byteCount() {
|
|
String[] strArr = this.namesAndValues;
|
|
long length = strArr.length << 1;
|
|
for (int i = 0; i < strArr.length; i++) {
|
|
length += this.namesAndValues[i].length();
|
|
}
|
|
return length;
|
|
}
|
|
|
|
@Override // java.lang.Iterable
|
|
public final Iterator<C13396fZU<? extends String, ? extends String>> iterator() {
|
|
int size = size();
|
|
C13396fZU[] c13396fZUArr = new C13396fZU[size];
|
|
for (int i = 0; i < size; i++) {
|
|
c13396fZUArr[i] = new C13396fZU(name(i), value(i));
|
|
}
|
|
C14957gcv.e(c13396fZUArr, "");
|
|
return new C14947gcl(c13396fZUArr);
|
|
}
|
|
|
|
public final Builder newBuilder() {
|
|
Builder builder = new Builder();
|
|
List<String> namesAndValues$okhttp = builder.getNamesAndValues$okhttp();
|
|
String[] strArr = this.namesAndValues;
|
|
C14957gcv.e(namesAndValues$okhttp, "");
|
|
C14957gcv.e(strArr, "");
|
|
C14957gcv.e(strArr, "");
|
|
List asList = Arrays.asList(strArr);
|
|
C14957gcv.c(asList, "");
|
|
namesAndValues$okhttp.addAll(asList);
|
|
return builder;
|
|
}
|
|
|
|
public final boolean equals(Object obj) {
|
|
return (obj instanceof Headers) && Arrays.equals(this.namesAndValues, ((Headers) obj).namesAndValues);
|
|
}
|
|
|
|
public final int hashCode() {
|
|
return Arrays.hashCode(this.namesAndValues);
|
|
}
|
|
|
|
public final String toString() {
|
|
StringBuilder sb = new StringBuilder();
|
|
int size = size();
|
|
for (int i = 0; i < size; i++) {
|
|
String name = name(i);
|
|
String value = value(i);
|
|
sb.append(name);
|
|
sb.append(": ");
|
|
if (Util.isSensitiveHeader(name)) {
|
|
value = "██";
|
|
}
|
|
sb.append(value);
|
|
sb.append("\n");
|
|
}
|
|
String obj = sb.toString();
|
|
C14957gcv.c((Object) obj, "");
|
|
return obj;
|
|
}
|
|
|
|
public final Map<String, List<String>> toMultimap() {
|
|
C14957gcv.e(gcH.d, "");
|
|
Comparator comparator = String.CASE_INSENSITIVE_ORDER;
|
|
C14957gcv.c(comparator, "");
|
|
TreeMap treeMap = new TreeMap(comparator);
|
|
int size = size();
|
|
for (int i = 0; i < size; i++) {
|
|
String name = name(i);
|
|
Locale locale = Locale.US;
|
|
C14957gcv.c(locale, "");
|
|
String lowerCase = name.toLowerCase(locale);
|
|
C14957gcv.c((Object) lowerCase, "");
|
|
ArrayList arrayList = (List) treeMap.get(lowerCase);
|
|
if (arrayList == null) {
|
|
arrayList = new ArrayList(2);
|
|
treeMap.put(lowerCase, arrayList);
|
|
}
|
|
arrayList.add(value(i));
|
|
}
|
|
return treeMap;
|
|
}
|
|
|
|
/* loaded from: classes.dex */
|
|
public static final class Builder {
|
|
private final List<String> namesAndValues = new ArrayList(20);
|
|
|
|
public final Builder addLenient$okhttp(String str) {
|
|
C14957gcv.e(str, "");
|
|
int a = gdZ.a((CharSequence) str, ':', 1, false);
|
|
if (a != -1) {
|
|
String substring = str.substring(0, a);
|
|
C14957gcv.c((Object) substring, "");
|
|
String substring2 = str.substring(a + 1);
|
|
C14957gcv.c((Object) substring2, "");
|
|
addLenient$okhttp(substring, substring2);
|
|
} else if (str.charAt(0) == ':') {
|
|
String substring3 = str.substring(1);
|
|
C14957gcv.c((Object) substring3, "");
|
|
addLenient$okhttp("", substring3);
|
|
} else {
|
|
addLenient$okhttp("", str);
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public final Builder add(String str) {
|
|
C14957gcv.e(str, "");
|
|
int a = gdZ.a((CharSequence) str, ':', 0, false);
|
|
if (a == -1) {
|
|
throw new IllegalArgumentException(C14957gcv.c("Unexpected header: ", (Object) str).toString());
|
|
}
|
|
String substring = str.substring(0, a);
|
|
C14957gcv.c((Object) substring, "");
|
|
String obj = gdZ.b((CharSequence) substring).toString();
|
|
String substring2 = str.substring(a + 1);
|
|
C14957gcv.c((Object) substring2, "");
|
|
add(obj, substring2);
|
|
return this;
|
|
}
|
|
|
|
public final Builder add(String str, String str2) {
|
|
C14957gcv.e(str, "");
|
|
C14957gcv.e(str2, "");
|
|
Headers.Companion.checkName(str);
|
|
Headers.Companion.checkValue(str2, str);
|
|
addLenient$okhttp(str, str2);
|
|
return this;
|
|
}
|
|
|
|
public final Builder addUnsafeNonAscii(String str, String str2) {
|
|
C14957gcv.e(str, "");
|
|
C14957gcv.e(str2, "");
|
|
Headers.Companion.checkName(str);
|
|
addLenient$okhttp(str, str2);
|
|
return this;
|
|
}
|
|
|
|
public final Builder addAll(Headers headers) {
|
|
C14957gcv.e(headers, "");
|
|
int size = headers.size();
|
|
for (int i = 0; i < size; i++) {
|
|
addLenient$okhttp(headers.name(i), headers.value(i));
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public final Builder add(String str, Date date) {
|
|
C14957gcv.e(str, "");
|
|
C14957gcv.e(date, "");
|
|
add(str, DatesKt.toHttpDateString(date));
|
|
return this;
|
|
}
|
|
|
|
public final Builder add(String str, Instant instant) {
|
|
C14957gcv.e(str, "");
|
|
C14957gcv.e(instant, "");
|
|
add(str, new Date(instant.toEpochMilli()));
|
|
return this;
|
|
}
|
|
|
|
public final Builder set(String str, Date date) {
|
|
C14957gcv.e(str, "");
|
|
C14957gcv.e(date, "");
|
|
set(str, DatesKt.toHttpDateString(date));
|
|
return this;
|
|
}
|
|
|
|
public final Builder set(String str, Instant instant) {
|
|
C14957gcv.e(str, "");
|
|
C14957gcv.e(instant, "");
|
|
return set(str, new Date(instant.toEpochMilli()));
|
|
}
|
|
|
|
public final Builder addLenient$okhttp(String str, String str2) {
|
|
C14957gcv.e(str, "");
|
|
C14957gcv.e(str2, "");
|
|
getNamesAndValues$okhttp().add(str);
|
|
getNamesAndValues$okhttp().add(gdZ.b((CharSequence) str2).toString());
|
|
return this;
|
|
}
|
|
|
|
public final Builder removeAll(String str) {
|
|
C14957gcv.e(str, "");
|
|
int i = 0;
|
|
while (i < getNamesAndValues$okhttp().size()) {
|
|
if (gdZ.a(str, getNamesAndValues$okhttp().get(i), true)) {
|
|
getNamesAndValues$okhttp().remove(i);
|
|
getNamesAndValues$okhttp().remove(i);
|
|
i -= 2;
|
|
}
|
|
i += 2;
|
|
}
|
|
return this;
|
|
}
|
|
|
|
public final Builder set(String str, String str2) {
|
|
C14957gcv.e(str, "");
|
|
C14957gcv.e(str2, "");
|
|
Headers.Companion.checkName(str);
|
|
Headers.Companion.checkValue(str2, str);
|
|
removeAll(str);
|
|
addLenient$okhttp(str, str2);
|
|
return this;
|
|
}
|
|
|
|
public final String get(String str) {
|
|
C14957gcv.e(str, "");
|
|
int size = this.namesAndValues.size() - 2;
|
|
int a = gbB.a(size, 0, -2);
|
|
if (a > size) {
|
|
return null;
|
|
}
|
|
while (!gdZ.a(str, this.namesAndValues.get(size), true)) {
|
|
if (size == a) {
|
|
return null;
|
|
}
|
|
size -= 2;
|
|
}
|
|
return this.namesAndValues.get(size + 1);
|
|
}
|
|
|
|
public final Headers build() {
|
|
Object[] array = this.namesAndValues.toArray(new String[0]);
|
|
if (array != null) {
|
|
return new Headers((String[]) array, null);
|
|
}
|
|
throw new NullPointerException("null cannot be cast to non-null type kotlin.Array<T of kotlin.collections.ArraysKt__ArraysJVMKt.toTypedArray>");
|
|
}
|
|
|
|
public final List<String> getNamesAndValues$okhttp() {
|
|
return this.namesAndValues;
|
|
}
|
|
}
|
|
|
|
/* loaded from: classes.dex */
|
|
public static final class Companion {
|
|
private Companion() {
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public final String get(String[] strArr, String str) {
|
|
int length = strArr.length - 2;
|
|
int a = gbB.a(length, 0, -2);
|
|
if (a > length) {
|
|
return null;
|
|
}
|
|
while (!gdZ.a(str, strArr[length], true)) {
|
|
if (length == a) {
|
|
return null;
|
|
}
|
|
length -= 2;
|
|
}
|
|
return strArr[length + 1];
|
|
}
|
|
|
|
public final Headers of(String... strArr) {
|
|
C14957gcv.e(strArr, "");
|
|
if (strArr.length % 2 != 0) {
|
|
throw new IllegalArgumentException("Expected alternating header names and values".toString());
|
|
}
|
|
String[] strArr2 = (String[]) strArr.clone();
|
|
int length = strArr2.length;
|
|
int i = 0;
|
|
for (int i2 = 0; i2 < length; i2++) {
|
|
String str = strArr2[i2];
|
|
if (str == null) {
|
|
throw new IllegalArgumentException("Headers cannot be null".toString());
|
|
}
|
|
strArr2[i2] = gdZ.b((CharSequence) str).toString();
|
|
}
|
|
int a = gbB.a(0, strArr2.length - 1, 2);
|
|
if (a >= 0) {
|
|
while (true) {
|
|
String str2 = strArr2[i];
|
|
String str3 = strArr2[i + 1];
|
|
checkName(str2);
|
|
checkValue(str3, str2);
|
|
if (i == a) {
|
|
break;
|
|
}
|
|
i += 2;
|
|
}
|
|
}
|
|
return new Headers(strArr2, null);
|
|
}
|
|
|
|
/* renamed from: -deprecated_of, reason: not valid java name */
|
|
public final Headers m407deprecated_of(String... strArr) {
|
|
C14957gcv.e(strArr, "");
|
|
return of((String[]) Arrays.copyOf(strArr, strArr.length));
|
|
}
|
|
|
|
public final Headers of(Map<String, String> map) {
|
|
C14957gcv.e(map, "");
|
|
String[] strArr = new String[map.size() << 1];
|
|
int i = 0;
|
|
for (Map.Entry<String, String> entry : map.entrySet()) {
|
|
String key = entry.getKey();
|
|
String value = entry.getValue();
|
|
String obj = gdZ.b((CharSequence) key).toString();
|
|
String obj2 = gdZ.b((CharSequence) value).toString();
|
|
checkName(obj);
|
|
checkValue(obj2, obj);
|
|
strArr[i] = obj;
|
|
strArr[i + 1] = obj2;
|
|
i += 2;
|
|
}
|
|
return new Headers(strArr, null);
|
|
}
|
|
|
|
/* renamed from: -deprecated_of, reason: not valid java name */
|
|
public final Headers m406deprecated_of(Map<String, String> map) {
|
|
C14957gcv.e(map, "");
|
|
return of(map);
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public final void checkName(String str) {
|
|
if (str.length() <= 0) {
|
|
throw new IllegalArgumentException("name is empty".toString());
|
|
}
|
|
int length = str.length();
|
|
for (int i = 0; i < length; i++) {
|
|
char charAt = str.charAt(i);
|
|
if ('!' > charAt || charAt >= 127) {
|
|
throw new IllegalArgumentException(Util.format("Unexpected char %#04x at %d in header name: %s", Integer.valueOf(charAt), Integer.valueOf(i), str).toString());
|
|
}
|
|
}
|
|
}
|
|
|
|
/* JADX INFO: Access modifiers changed from: private */
|
|
public final void checkValue(String str, String str2) {
|
|
int length = str.length();
|
|
for (int i = 0; i < length; i++) {
|
|
char charAt = str.charAt(i);
|
|
if (charAt != '\t' && (' ' > charAt || charAt >= 127)) {
|
|
throw new IllegalArgumentException(C14957gcv.c(Util.format("Unexpected char %#04x at %d in %s value", Integer.valueOf(charAt), Integer.valueOf(i), str2), (Object) (Util.isSensitiveHeader(str2) ? "" : C14957gcv.c(": ", (Object) str))).toString());
|
|
}
|
|
}
|
|
}
|
|
|
|
public /* synthetic */ Companion(C14953gcr c14953gcr) {
|
|
this();
|
|
}
|
|
}
|
|
|
|
public static final Headers of(String... strArr) {
|
|
return Companion.of(strArr);
|
|
}
|
|
|
|
public static final Headers of(Map<String, String> map) {
|
|
return Companion.of(map);
|
|
}
|
|
|
|
public /* synthetic */ Headers(String[] strArr, C14953gcr c14953gcr) {
|
|
this(strArr);
|
|
}
|
|
}
|