package okhttp3; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import okhttp3.Headers; import okhttp3.internal.Util; import okhttp3.internal.http.HttpMethod; /* loaded from: classes5.dex */ public final class Request { public final RequestBody body; public volatile CacheControl cacheControl; public final Headers headers; public final String method; public final Map tags; public final HttpUrl url; public RequestBody body() { return this.body; } public Headers headers() { return this.headers; } public String method() { return this.method; } public HttpUrl url() { return this.url; } public Request(Builder builder) { this.url = builder.url; this.method = builder.method; this.headers = builder.headers.build(); this.body = builder.body; this.tags = Util.immutableMap(builder.tags); } public String header(String str) { return this.headers.get(str); } public List headers(String str) { return this.headers.values(str); } public Builder newBuilder() { return new Builder(this); } public CacheControl cacheControl() { CacheControl cacheControl = this.cacheControl; if (cacheControl != null) { return cacheControl; } CacheControl parse = CacheControl.parse(this.headers); this.cacheControl = parse; return parse; } public boolean isHttps() { return this.url.isHttps(); } public String toString() { return "Request{method=" + this.method + ", url=" + this.url + ", tags=" + this.tags + '}'; } public static class Builder { public RequestBody body; public Headers.Builder headers; public String method; public Map tags; public HttpUrl url; public Builder() { this.tags = Collections.emptyMap(); this.method = "GET"; this.headers = new Headers.Builder(); } public Builder(Request request) { Map linkedHashMap; this.tags = Collections.emptyMap(); this.url = request.url; this.method = request.method; this.body = request.body; if (request.tags.isEmpty()) { linkedHashMap = Collections.emptyMap(); } else { linkedHashMap = new LinkedHashMap(request.tags); } this.tags = linkedHashMap; this.headers = request.headers.newBuilder(); } public Builder url(HttpUrl httpUrl) { if (httpUrl == null) { throw new NullPointerException("url == null"); } this.url = httpUrl; return this; } public Builder url(String str) { if (str == null) { throw new NullPointerException("url == null"); } if (str.regionMatches(true, 0, "ws:", 0, 3)) { str = "http:" + str.substring(3); } else if (str.regionMatches(true, 0, "wss:", 0, 4)) { str = "https:" + str.substring(4); } return url(HttpUrl.get(str)); } public Builder header(String str, String str2) { this.headers.set(str, str2); return this; } public Builder addHeader(String str, String str2) { this.headers.add(str, str2); return this; } public Builder removeHeader(String str) { this.headers.removeAll(str); return this; } public Builder headers(Headers headers) { this.headers = headers.newBuilder(); return this; } public Builder get() { return method("GET", null); } public Builder post(RequestBody requestBody) { return method("POST", requestBody); } public Builder method(String str, RequestBody requestBody) { if (str == null) { throw new NullPointerException("method == null"); } if (str.length() == 0) { throw new IllegalArgumentException("method.length() == 0"); } if (requestBody != null && !HttpMethod.permitsRequestBody(str)) { throw new IllegalArgumentException("method " + str + " must not have a request body."); } if (requestBody != null || !HttpMethod.requiresRequestBody(str)) { this.method = str; this.body = requestBody; return this; } throw new IllegalArgumentException("method " + str + " must have a request body."); } public Request build() { if (this.url == null) { throw new IllegalStateException("url == null"); } return new Request(this); } } }