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

329 lines
9.1 KiB
Java
Raw Permalink Normal View History

2024-07-27 18:17:47 +07:00
package okhttp3.repackaged;
import com.airbnb.deeplinkdispatch.UrlTreeKt;
import com.google.common.net.HttpHeaders;
import java.io.EOFException;
import java.io.IOException;
import java.util.Collections;
import java.util.List;
import o.InterfaceC15142giR;
import o.giM;
import okhttp3.repackaged.Headers;
import okhttp3.repackaged.internal.http.OkHeaders;
/* loaded from: classes6.dex */
public final class Response {
private final Handshake agZ;
private volatile CacheControl aiB;
private final ResponseBody aiF;
private Response aiG;
private final Response aiH;
private final Headers aii;
private final Request aix;
private Response cacheResponse;
private final int code;
private final String message;
private final Protocol protocol;
private Response(Builder builder) {
this.aix = builder.aix;
this.protocol = builder.protocol;
this.code = builder.code;
this.message = builder.message;
this.agZ = builder.agZ;
this.aii = builder.aiC.build();
this.aiF = builder.aiF;
this.aiG = builder.aiG;
this.cacheResponse = builder.cacheResponse;
this.aiH = builder.aiH;
}
public final List<String> headers(String str) {
return this.aii.values(str);
}
public final String header(String str) {
return header(str, null);
}
public final String header(String str, String str2) {
String str3 = this.aii.get(str);
return str3 != null ? str3 : str2;
}
public final ResponseBody peekBody(long j) throws IOException {
InterfaceC15142giR source = this.aiF.source();
source.a(j);
giM clone = source.b().clone();
if (clone.a > j) {
giM gim = new giM();
gim.write(clone, j);
try {
clone.f(clone.a);
clone = gim;
} catch (EOFException e) {
throw new AssertionError(e);
}
}
return ResponseBody.create(this.aiF.contentType(), clone.a, clone);
}
public final Builder newBuilder() {
return new Builder();
}
public final List<Challenge> challenges() {
String str;
int i = this.code;
if (i == 401) {
str = HttpHeaders.WWW_AUTHENTICATE;
} else {
if (i != 407) {
return Collections.emptyList();
}
str = HttpHeaders.PROXY_AUTHENTICATE;
}
return OkHeaders.parseChallenges(headers(), str);
}
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 String toString() {
StringBuilder sb = new StringBuilder("Response{protocol=");
sb.append(this.protocol);
sb.append(", code=");
sb.append(this.code);
sb.append(", message=");
sb.append(this.message);
sb.append(", url=");
sb.append(this.aix.url());
sb.append(UrlTreeKt.componentParamSuffixChar);
return sb.toString();
}
/* loaded from: classes6.dex */
public static class Builder {
private Handshake agZ;
private Headers.Builder aiC;
private ResponseBody aiF;
private Response aiG;
private Response aiH;
private Request aix;
private Response cacheResponse;
private int code;
private String message;
private Protocol protocol;
public Builder() {
this.code = -1;
this.aiC = new Headers.Builder();
}
private Builder(Response response) {
this.code = -1;
this.aix = response.aix;
this.protocol = response.protocol;
this.code = response.code;
this.message = response.message;
this.agZ = response.agZ;
this.aiC = response.aii.newBuilder();
this.aiF = response.aiF;
this.aiG = response.aiG;
this.cacheResponse = response.cacheResponse;
this.aiH = response.aiH;
}
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 networkResponse(Response response) {
if (response != null) {
a("networkResponse", response);
}
this.aiG = response;
return this;
}
public Builder cacheResponse(Response response) {
if (response != null) {
a("cacheResponse", response);
}
this.cacheResponse = response;
return this;
}
private void a(String str, Response response) {
if (response.aiF == null) {
if (response.aiG == null) {
if (response.cacheResponse == null) {
if (response.aiH == null) {
return;
}
StringBuilder sb = new StringBuilder();
sb.append(str);
sb.append(".priorResponse != null");
throw new IllegalArgumentException(sb.toString());
}
StringBuilder sb2 = new StringBuilder();
sb2.append(str);
sb2.append(".cacheResponse != null");
throw new IllegalArgumentException(sb2.toString());
}
StringBuilder sb3 = new StringBuilder();
sb3.append(str);
sb3.append(".networkResponse != null");
throw new IllegalArgumentException(sb3.toString());
}
StringBuilder sb4 = new StringBuilder();
sb4.append(str);
sb4.append(".body != null");
throw new IllegalArgumentException(sb4.toString());
}
public Builder priorResponse(Response response) {
if (response != null) {
k(response);
}
this.aiH = response;
return this;
}
private void k(Response response) {
if (response.aiF != null) {
throw new IllegalArgumentException("priorResponse.body != null");
}
}
public Response build() {
if (this.aix == null) {
throw new IllegalStateException("request == null");
}
if (this.protocol == null) {
throw new IllegalStateException("protocol == null");
}
if (this.code < 0) {
StringBuilder sb = new StringBuilder("code < 0: ");
sb.append(this.code);
throw new IllegalStateException(sb.toString());
}
return new Response(this);
}
public Builder request(Request request) {
this.aix = request;
return this;
}
public Builder protocol(Protocol protocol) {
this.protocol = protocol;
return this;
}
public Builder message(String str) {
this.message = str;
return this;
}
public Builder handshake(Handshake handshake) {
this.agZ = handshake;
return this;
}
public Builder code(int i) {
this.code = i;
return this;
}
public Builder body(ResponseBody responseBody) {
this.aiF = responseBody;
return this;
}
}
public final Request request() {
return this.aix;
}
public final Protocol protocol() {
return this.protocol;
}
public final Response priorResponse() {
return this.aiH;
}
public final Response networkResponse() {
return this.aiG;
}
public final String message() {
return this.message;
}
public final boolean isSuccessful() {
int i = this.code;
return i >= 200 && i < 300;
}
public final boolean isRedirect() {
int i = this.code;
if (i == 307 || i == 308) {
return true;
}
switch (i) {
case 300:
case 301:
case 302:
case 303:
return true;
default:
return false;
}
}
public final Headers headers() {
return this.aii;
}
public final Handshake handshake() {
return this.agZ;
}
public final int code() {
return this.code;
}
public final Response cacheResponse() {
return this.cacheResponse;
}
public final ResponseBody body() {
return this.aiF;
}
}