what-the-bank/sources/okhttp3/repackaged/Request.java

238 lines
6.9 KiB
Java

package okhttp3.repackaged;
import com.airbnb.deeplinkdispatch.UrlTreeKt;
import com.google.common.net.HttpHeaders;
import io.grpc.internal.GrpcUtil;
import java.net.URI;
import java.net.URL;
import java.util.List;
import okhttp3.repackaged.Headers;
import okhttp3.repackaged.internal.http.HttpMethod;
/* loaded from: classes6.dex */
public final class Request {
private final HttpUrl agw;
private volatile URI aiA;
private volatile CacheControl aiB;
private final Headers aii;
private final RequestBody aij;
private final String method;
private final Object tag;
private Request(Builder builder) {
this.agw = builder.agw;
this.method = builder.method;
this.aii = builder.aiC.build();
this.aij = builder.aij;
this.tag = builder.tag != null ? builder.tag : this;
}
public final String header(String str) {
return this.aii.get(str);
}
public final List<String> headers(String str) {
return this.aii.values(str);
}
public final Builder newBuilder() {
return new Builder();
}
public final CacheControl cacheControl() {
CacheControl cacheControl = this.aiB;
if (cacheControl != null) {
return cacheControl;
}
CacheControl parse = CacheControl.parse(this.aii);
this.aiB = parse;
return parse;
}
public final boolean isHttps() {
return this.agw.isHttps();
}
public final String toString() {
StringBuilder sb = new StringBuilder("Request{method=");
sb.append(this.method);
sb.append(", url=");
sb.append(this.agw);
sb.append(", tag=");
Object obj = this.tag;
if (obj == this) {
obj = null;
}
sb.append(obj);
sb.append(UrlTreeKt.componentParamSuffixChar);
return sb.toString();
}
/* loaded from: classes6.dex */
public static class Builder {
private HttpUrl agw;
private Headers.Builder aiC;
private RequestBody aij;
private String method;
private Object tag;
public Builder() {
this.method = "GET";
this.aiC = new Headers.Builder();
}
private Builder(Request request) {
this.agw = request.agw;
this.method = request.method;
this.aij = request.aij;
this.tag = request.tag;
this.aiC = request.aii.newBuilder();
}
public Builder url(HttpUrl httpUrl) {
if (httpUrl == null) {
throw new IllegalArgumentException("url == null");
}
this.agw = httpUrl;
return this;
}
public Builder url(String str) {
if (str == null) {
throw new IllegalArgumentException("url == null");
}
if (str.regionMatches(true, 0, "ws:", 0, 3)) {
StringBuilder sb = new StringBuilder("http:");
sb.append(str.substring(3));
str = sb.toString();
} else if (str.regionMatches(true, 0, "wss:", 0, 4)) {
StringBuilder sb2 = new StringBuilder("https:");
sb2.append(str.substring(4));
str = sb2.toString();
}
HttpUrl parse = HttpUrl.parse(str);
if (parse == null) {
throw new IllegalArgumentException("unexpected url: ".concat(String.valueOf(str)));
}
return url(parse);
}
public Builder url(URL url) {
if (url == null) {
throw new IllegalArgumentException("url == null");
}
HttpUrl httpUrl = HttpUrl.get(url);
if (httpUrl == null) {
throw new IllegalArgumentException("unexpected url: ".concat(String.valueOf(url)));
}
return url(httpUrl);
}
public Builder header(String str, String str2) {
this.aiC.set(str, str2);
return this;
}
public Builder addHeader(String str, String str2) {
this.aiC.add(str, str2);
return this;
}
public Builder removeHeader(String str) {
this.aiC.removeAll(str);
return this;
}
public Builder headers(Headers headers) {
this.aiC = headers.newBuilder();
return this;
}
public Builder cacheControl(CacheControl cacheControl) {
String obj = cacheControl.toString();
return obj.isEmpty() ? removeHeader(HttpHeaders.CACHE_CONTROL) : header(HttpHeaders.CACHE_CONTROL, obj);
}
public Builder get() {
return method("GET", null);
}
public Builder head() {
return method("HEAD", null);
}
public Builder post(RequestBody requestBody) {
return method(GrpcUtil.HTTP_METHOD, requestBody);
}
public Builder delete(RequestBody requestBody) {
return method("DELETE", requestBody);
}
public Builder delete() {
return delete(RequestBody.create((MediaType) null, new byte[0]));
}
public Builder put(RequestBody requestBody) {
return method("PUT", requestBody);
}
public Builder patch(RequestBody requestBody) {
return method("PATCH", requestBody);
}
public Builder method(String str, RequestBody requestBody) {
if (str == null || str.length() == 0) {
throw new IllegalArgumentException("method == null || method.length() == 0");
}
if (requestBody != null && !HttpMethod.permitsRequestBody(str)) {
StringBuilder sb = new StringBuilder("method ");
sb.append(str);
sb.append(" must not have a request body.");
throw new IllegalArgumentException(sb.toString());
}
if (requestBody != null || !HttpMethod.requiresRequestBody(str)) {
this.method = str;
this.aij = requestBody;
return this;
}
StringBuilder sb2 = new StringBuilder("method ");
sb2.append(str);
sb2.append(" must have a request body.");
throw new IllegalArgumentException(sb2.toString());
}
public Request build() {
if (this.agw == null) {
throw new IllegalStateException("url == null");
}
return new Request(this);
}
public Builder tag(Object obj) {
this.tag = obj;
return this;
}
}
public final HttpUrl url() {
return this.agw;
}
public final Object tag() {
return this.tag;
}
public final String method() {
return this.method;
}
public final Headers headers() {
return this.aii;
}
public final RequestBody body() {
return this.aij;
}
}