package com.mbridge.msdk.thrid.okhttp; import com.mbridge.msdk.thrid.okhttp.Headers; import com.mbridge.msdk.thrid.okhttp.internal.Util; import com.mbridge.msdk.thrid.okhttp.internal.http.HttpMethod; import java.net.URL; import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpHead; import org.apache.http.client.methods.HttpPut; /* loaded from: classes4.dex */ public final class Request { final RequestBody body; private volatile CacheControl cacheControl; final Headers headers; final String method; final Map, Object> tags; 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 Object tag() { return tag(Object.class); } public T tag(Class cls) { return cls.cast(this.tags.get(cls)); } 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 { RequestBody body; Headers.Builder headers; String method; Map, Object> tags; HttpUrl url; public Builder() { this.tags = Collections.emptyMap(); this.method = "GET"; this.headers = new Headers.Builder(); } public Builder(Request request) { this.tags = Collections.emptyMap(); this.url = request.url; this.method = request.method; this.body = request.body; this.tags = request.tags.isEmpty() ? Collections.emptyMap() : new LinkedHashMap<>(request.tags); 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 url(URL url) { if (url == null) { throw new NullPointerException("url == null"); } return url(HttpUrl.get(url.toString())); } 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 cacheControl(CacheControl cacheControl) { String cacheControl2 = cacheControl.toString(); return cacheControl2.isEmpty() ? removeHeader("Cache-Control") : header("Cache-Control", cacheControl2); } public Builder get() { return method("GET", null); } public Builder head() { return method(HttpHead.METHOD_NAME, null); } public Builder post(RequestBody requestBody) { return method("POST", requestBody); } public Builder delete(RequestBody requestBody) { return method(HttpDelete.METHOD_NAME, requestBody); } public Builder delete() { return delete(Util.EMPTY_REQUEST); } public Builder put(RequestBody requestBody) { return method(HttpPut.METHOD_NAME, requestBody); } public Builder patch(RequestBody requestBody) { return method("PATCH", 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 Builder tag(Object obj) { return tag(Object.class, obj); } public Builder tag(Class cls, T t) { if (cls == null) { throw new NullPointerException("type == null"); } if (t == null) { this.tags.remove(cls); } else { if (this.tags.isEmpty()) { this.tags = new LinkedHashMap(); } this.tags.put(cls, cls.cast(t)); } return this; } public Request build() { if (this.url == null) { throw new IllegalStateException("url == null"); } return new Request(this); } } }