package okhttp3; import com.airbnb.deeplinkdispatch.UrlTreeKt; import com.google.common.net.HttpHeaders; import java.io.Closeable; import java.io.EOFException; import java.io.IOException; import java.util.List; import o.C14851gaI; import o.C14957gcv; import o.C15111ghZ; import o.InterfaceC15149gid; import okhttp3.Headers; import okhttp3.internal.connection.Exchange; /* loaded from: classes.dex */ public final class Response implements Closeable { private final ResponseBody body; private final Response cacheResponse; private final int code; private final Exchange exchange; private final Handshake handshake; private final Headers headers; private CacheControl lazyCacheControl; private final String message; private final Response networkResponse; private final Response priorResponse; private final Protocol protocol; private final long receivedResponseAtMillis; private final Request request; private final long sentRequestAtMillis; public Response(Request request, Protocol protocol, String str, int i, Handshake handshake, Headers headers, ResponseBody responseBody, Response response, Response response2, Response response3, long j, long j2, Exchange exchange) { C14957gcv.e(request, ""); C14957gcv.e(protocol, ""); C14957gcv.e(str, ""); C14957gcv.e(headers, ""); this.request = request; this.protocol = protocol; this.message = str; this.code = i; this.handshake = handshake; this.headers = headers; this.body = responseBody; this.networkResponse = response; this.cacheResponse = response2; this.priorResponse = response3; this.sentRequestAtMillis = j; this.receivedResponseAtMillis = j2; this.exchange = exchange; } public final List headers(String str) { C14957gcv.e(str, ""); return this.headers.values(str); } public static /* synthetic */ String header$default(Response response, String str, String str2, int i, Object obj) { if ((i & 2) != 0) { str2 = null; } return response.header(str, str2); } public final String header(String str, String str2) { C14957gcv.e(str, ""); String str3 = this.headers.get(str); return str3 == null ? str2 : str3; } public final Headers trailers() throws IOException { Exchange exchange = this.exchange; if (exchange != null) { return exchange.trailers(); } throw new IllegalStateException("trailers not available".toString()); } public final ResponseBody peekBody(long j) throws IOException { ResponseBody responseBody = this.body; C14957gcv.e(responseBody); InterfaceC15149gid g = responseBody.source().g(); C15111ghZ c15111ghZ = new C15111ghZ(); g.a(j); InterfaceC15149gid interfaceC15149gid = g; long min = Math.min(j, g.i().c); C14957gcv.e(interfaceC15149gid, ""); while (min > 0) { long read = interfaceC15149gid.read(c15111ghZ, min); if (read == -1) { throw new EOFException(); } min -= read; } return ResponseBody.Companion.create(c15111ghZ, this.body.contentType(), c15111ghZ.c); } public final Builder newBuilder() { return new Builder(this); } public final CacheControl cacheControl() { CacheControl cacheControl = this.lazyCacheControl; if (cacheControl != null) { return cacheControl; } CacheControl parse = CacheControl.Companion.parse(this.headers); this.lazyCacheControl = parse; return parse; } /* renamed from: -deprecated_cacheControl, reason: not valid java name */ public final CacheControl m475deprecated_cacheControl() { return cacheControl(); } @Override // java.io.Closeable, java.lang.AutoCloseable public final void close() { ResponseBody responseBody = this.body; if (responseBody == null) { throw new IllegalStateException("response is not eligible for a body and must not be closed".toString()); } responseBody.close(); } 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.request.url()); sb.append(UrlTreeKt.componentParamSuffixChar); return sb.toString(); } /* loaded from: classes.dex */ public static class Builder { private ResponseBody body; private Response cacheResponse; private int code; private Exchange exchange; private Handshake handshake; private Headers.Builder headers; private String message; private Response networkResponse; private Response priorResponse; private Protocol protocol; private long receivedResponseAtMillis; private Request request; private long sentRequestAtMillis; public Builder() { this.code = -1; this.headers = new Headers.Builder(); } public Builder(Response response) { C14957gcv.e(response, ""); this.code = -1; this.request = response.request(); this.protocol = response.protocol(); this.code = response.code(); this.message = response.message(); this.handshake = response.handshake(); this.headers = response.headers().newBuilder(); this.body = response.body(); this.networkResponse = response.networkResponse(); this.cacheResponse = response.cacheResponse(); this.priorResponse = response.priorResponse(); this.sentRequestAtMillis = response.sentRequestAtMillis(); this.receivedResponseAtMillis = response.receivedResponseAtMillis(); this.exchange = response.exchange(); } public Builder request(Request request) { C14957gcv.e(request, ""); setRequest$okhttp(request); return this; } public Builder protocol(Protocol protocol) { C14957gcv.e(protocol, ""); setProtocol$okhttp(protocol); return this; } public Builder code(int i) { setCode$okhttp(i); return this; } public Builder message(String str) { C14957gcv.e(str, ""); setMessage$okhttp(str); return this; } public Builder handshake(Handshake handshake) { setHandshake$okhttp(handshake); return this; } public Builder header(String str, String str2) { C14957gcv.e(str, ""); C14957gcv.e(str2, ""); getHeaders$okhttp().set(str, str2); return this; } public Builder addHeader(String str, String str2) { C14957gcv.e(str, ""); C14957gcv.e(str2, ""); getHeaders$okhttp().add(str, str2); return this; } public Builder removeHeader(String str) { C14957gcv.e(str, ""); getHeaders$okhttp().removeAll(str); return this; } public Builder headers(Headers headers) { C14957gcv.e(headers, ""); setHeaders$okhttp(headers.newBuilder()); return this; } public Builder body(ResponseBody responseBody) { setBody$okhttp(responseBody); return this; } public Builder networkResponse(Response response) { checkSupportResponse("networkResponse", response); setNetworkResponse$okhttp(response); return this; } public Builder cacheResponse(Response response) { checkSupportResponse("cacheResponse", response); setCacheResponse$okhttp(response); return this; } private final void checkSupportResponse(String str, Response response) { if (response != null) { if (response.body() != null) { throw new IllegalArgumentException(C14957gcv.c(str, (Object) ".body != null").toString()); } if (response.networkResponse() != null) { throw new IllegalArgumentException(C14957gcv.c(str, (Object) ".networkResponse != null").toString()); } if (response.cacheResponse() != null) { throw new IllegalArgumentException(C14957gcv.c(str, (Object) ".cacheResponse != null").toString()); } if (response.priorResponse() != null) { throw new IllegalArgumentException(C14957gcv.c(str, (Object) ".priorResponse != null").toString()); } } } public Builder priorResponse(Response response) { checkPriorResponse(response); setPriorResponse$okhttp(response); return this; } private final void checkPriorResponse(Response response) { if (response != null && response.body() != null) { throw new IllegalArgumentException("priorResponse.body != null".toString()); } } public Builder sentRequestAtMillis(long j) { setSentRequestAtMillis$okhttp(j); return this; } public Builder receivedResponseAtMillis(long j) { setReceivedResponseAtMillis$okhttp(j); return this; } public Response build() { int i = this.code; if (i < 0) { throw new IllegalStateException(C14957gcv.c("code < 0: ", Integer.valueOf(getCode$okhttp())).toString()); } Request request = this.request; if (request == null) { throw new IllegalStateException("request == null".toString()); } Protocol protocol = this.protocol; if (protocol == null) { throw new IllegalStateException("protocol == null".toString()); } String str = this.message; if (str != null) { return new Response(request, protocol, str, i, this.handshake, this.headers.build(), this.body, this.networkResponse, this.cacheResponse, this.priorResponse, this.sentRequestAtMillis, this.receivedResponseAtMillis, this.exchange); } throw new IllegalStateException("message == null".toString()); } public final void setSentRequestAtMillis$okhttp(long j) { this.sentRequestAtMillis = j; } public final void setRequest$okhttp(Request request) { this.request = request; } public final void setReceivedResponseAtMillis$okhttp(long j) { this.receivedResponseAtMillis = j; } public final void setProtocol$okhttp(Protocol protocol) { this.protocol = protocol; } public final void setPriorResponse$okhttp(Response response) { this.priorResponse = response; } public final void setNetworkResponse$okhttp(Response response) { this.networkResponse = response; } public final void setMessage$okhttp(String str) { this.message = str; } public final void setHeaders$okhttp(Headers.Builder builder) { C14957gcv.e(builder, ""); this.headers = builder; } public final void setHandshake$okhttp(Handshake handshake) { this.handshake = handshake; } public final void setExchange$okhttp(Exchange exchange) { this.exchange = exchange; } public final void setCode$okhttp(int i) { this.code = i; } public final void setCacheResponse$okhttp(Response response) { this.cacheResponse = response; } public final void setBody$okhttp(ResponseBody responseBody) { this.body = responseBody; } public final void initExchange$okhttp(Exchange exchange) { C14957gcv.e(exchange, ""); this.exchange = exchange; } public final long getSentRequestAtMillis$okhttp() { return this.sentRequestAtMillis; } public final Request getRequest$okhttp() { return this.request; } public final long getReceivedResponseAtMillis$okhttp() { return this.receivedResponseAtMillis; } public final Protocol getProtocol$okhttp() { return this.protocol; } public final Response getPriorResponse$okhttp() { return this.priorResponse; } public final Response getNetworkResponse$okhttp() { return this.networkResponse; } public final String getMessage$okhttp() { return this.message; } public final Headers.Builder getHeaders$okhttp() { return this.headers; } public final Handshake getHandshake$okhttp() { return this.handshake; } public final Exchange getExchange$okhttp() { return this.exchange; } public final int getCode$okhttp() { return this.code; } public final Response getCacheResponse$okhttp() { return this.cacheResponse; } public final ResponseBody getBody$okhttp() { return this.body; } } public final List challenges() { String str; Headers headers = this.headers; int i = this.code; if (i == 401) { str = HttpHeaders.WWW_AUTHENTICATE; } else { if (i != 407) { return C14851gaI.c; } str = HttpHeaders.PROXY_AUTHENTICATE; } return okhttp3.internal.http.HttpHeaders.parseChallenges(headers, str); } public final long sentRequestAtMillis() { return this.sentRequestAtMillis; } public final Request request() { return this.request; } public final long receivedResponseAtMillis() { return this.receivedResponseAtMillis; } public final Protocol protocol() { return this.protocol; } public final Response priorResponse() { return this.priorResponse; } public final Response networkResponse() { return this.networkResponse; } public final String message() { return this.message; } public final boolean isSuccessful() { int i = this.code; return 200 <= i && i < 300; } public final boolean isRedirect() { int i = this.code; if (i != 307 && i != 308) { switch (i) { case 300: case 301: case 302: case 303: break; default: return false; } } return true; } public final Headers headers() { return this.headers; } public final String header(String str) { C14957gcv.e(str, ""); return header$default(this, str, null, 2, null); } public final Handshake handshake() { return this.handshake; } public final Exchange exchange() { return this.exchange; } public final int code() { return this.code; } public final Response cacheResponse() { return this.cacheResponse; } public final ResponseBody body() { return this.body; } /* renamed from: -deprecated_sentRequestAtMillis, reason: not valid java name */ public final long m486deprecated_sentRequestAtMillis() { return this.sentRequestAtMillis; } /* renamed from: -deprecated_request, reason: not valid java name */ public final Request m485deprecated_request() { return this.request; } /* renamed from: -deprecated_receivedResponseAtMillis, reason: not valid java name */ public final long m484deprecated_receivedResponseAtMillis() { return this.receivedResponseAtMillis; } /* renamed from: -deprecated_protocol, reason: not valid java name */ public final Protocol m483deprecated_protocol() { return this.protocol; } /* renamed from: -deprecated_priorResponse, reason: not valid java name */ public final Response m482deprecated_priorResponse() { return this.priorResponse; } /* renamed from: -deprecated_networkResponse, reason: not valid java name */ public final Response m481deprecated_networkResponse() { return this.networkResponse; } /* renamed from: -deprecated_message, reason: not valid java name */ public final String m480deprecated_message() { return this.message; } /* renamed from: -deprecated_headers, reason: not valid java name */ public final Headers m479deprecated_headers() { return this.headers; } /* renamed from: -deprecated_handshake, reason: not valid java name */ public final Handshake m478deprecated_handshake() { return this.handshake; } /* renamed from: -deprecated_code, reason: not valid java name */ public final int m477deprecated_code() { return this.code; } /* renamed from: -deprecated_cacheResponse, reason: not valid java name */ public final Response m476deprecated_cacheResponse() { return this.cacheResponse; } /* renamed from: -deprecated_body, reason: not valid java name */ public final ResponseBody m474deprecated_body() { return this.body; } }