135 lines
3.8 KiB
Java
135 lines
3.8 KiB
Java
package com.bumptech.glide.load.model;
|
|
|
|
import android.text.TextUtils;
|
|
import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/* loaded from: classes.dex */
|
|
public final class LazyHeaders implements Headers {
|
|
private final Map<String, List<LazyHeaderFactory>> b;
|
|
private volatile Map<String, String> c;
|
|
|
|
public static final class Builder {
|
|
private static final String b = b();
|
|
private static final Map<String, List<LazyHeaderFactory>> c;
|
|
private Map<String, List<LazyHeaderFactory>> a = c;
|
|
|
|
static {
|
|
HashMap hashMap = new HashMap(2);
|
|
if (!TextUtils.isEmpty(b)) {
|
|
hashMap.put("User-Agent", Collections.singletonList(new StringHeaderFactory(b)));
|
|
}
|
|
c = Collections.unmodifiableMap(hashMap);
|
|
}
|
|
|
|
static String b() {
|
|
String property = System.getProperty("http.agent");
|
|
if (TextUtils.isEmpty(property)) {
|
|
return property;
|
|
}
|
|
int length = property.length();
|
|
StringBuilder sb = new StringBuilder(property.length());
|
|
for (int i = 0; i < length; i++) {
|
|
char charAt = property.charAt(i);
|
|
if ((charAt > 31 || charAt == '\t') && charAt < 127) {
|
|
sb.append(charAt);
|
|
} else {
|
|
sb.append('?');
|
|
}
|
|
}
|
|
return sb.toString();
|
|
}
|
|
|
|
public LazyHeaders a() {
|
|
return new LazyHeaders(this.a);
|
|
}
|
|
}
|
|
|
|
static final class StringHeaderFactory implements LazyHeaderFactory {
|
|
private final String a;
|
|
|
|
StringHeaderFactory(String str) {
|
|
this.a = str;
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.model.LazyHeaderFactory
|
|
public String a() {
|
|
return this.a;
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (obj instanceof StringHeaderFactory) {
|
|
return this.a.equals(((StringHeaderFactory) obj).a);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public int hashCode() {
|
|
return this.a.hashCode();
|
|
}
|
|
|
|
public String toString() {
|
|
return "StringHeaderFactory{value='" + this.a + "'}";
|
|
}
|
|
}
|
|
|
|
LazyHeaders(Map<String, List<LazyHeaderFactory>> map) {
|
|
this.b = Collections.unmodifiableMap(map);
|
|
}
|
|
|
|
private Map<String, String> b() {
|
|
HashMap hashMap = new HashMap();
|
|
for (Map.Entry<String, List<LazyHeaderFactory>> entry : this.b.entrySet()) {
|
|
String a = a(entry.getValue());
|
|
if (!TextUtils.isEmpty(a)) {
|
|
hashMap.put(entry.getKey(), a);
|
|
}
|
|
}
|
|
return hashMap;
|
|
}
|
|
|
|
@Override // com.bumptech.glide.load.model.Headers
|
|
public Map<String, String> a() {
|
|
if (this.c == null) {
|
|
synchronized (this) {
|
|
if (this.c == null) {
|
|
this.c = Collections.unmodifiableMap(b());
|
|
}
|
|
}
|
|
}
|
|
return this.c;
|
|
}
|
|
|
|
public boolean equals(Object obj) {
|
|
if (obj instanceof LazyHeaders) {
|
|
return this.b.equals(((LazyHeaders) obj).b);
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public int hashCode() {
|
|
return this.b.hashCode();
|
|
}
|
|
|
|
public String toString() {
|
|
return "LazyHeaders{headers=" + this.b + '}';
|
|
}
|
|
|
|
private String a(List<LazyHeaderFactory> list) {
|
|
StringBuilder sb = new StringBuilder();
|
|
int size = list.size();
|
|
for (int i = 0; i < size; i++) {
|
|
String a = list.get(i).a();
|
|
if (!TextUtils.isEmpty(a)) {
|
|
sb.append(a);
|
|
if (i != list.size() - 1) {
|
|
sb.append(',');
|
|
}
|
|
}
|
|
}
|
|
return sb.toString();
|
|
}
|
|
}
|