package okhttp3.repackaged.internal.http; import com.google.common.net.HttpHeaders; import java.util.Date; import java.util.concurrent.TimeUnit; import okhttp3.repackaged.CacheControl; import okhttp3.repackaged.Headers; import okhttp3.repackaged.Request; import okhttp3.repackaged.Response; /* loaded from: classes6.dex */ public final class CacheStrategy { public final Response cacheResponse; public final Request networkRequest; private CacheStrategy(Request request, Response response) { this.networkRequest = request; this.cacheResponse = response; } /* JADX WARN: Code restructure failed: missing block: B:31:0x0056, code lost: if (r3.cacheControl().isPrivate() == false) goto L32; */ /* Code decompiled incorrectly, please refer to instructions dump. To view partially-correct add '--show-bad-code' argument */ public static boolean isCacheable(okhttp3.repackaged.Response r3, okhttp3.repackaged.Request r4) { /* int r0 = r3.code() r1 = 200(0xc8, float:2.8E-43) r2 = 0 if (r0 == r1) goto L59 r1 = 410(0x19a, float:5.75E-43) if (r0 == r1) goto L59 r1 = 414(0x19e, float:5.8E-43) if (r0 == r1) goto L59 r1 = 501(0x1f5, float:7.02E-43) if (r0 == r1) goto L59 r1 = 203(0xcb, float:2.84E-43) if (r0 == r1) goto L59 r1 = 204(0xcc, float:2.86E-43) if (r0 == r1) goto L59 r1 = 307(0x133, float:4.3E-43) if (r0 == r1) goto L31 r1 = 308(0x134, float:4.32E-43) if (r0 == r1) goto L59 r1 = 404(0x194, float:5.66E-43) if (r0 == r1) goto L59 r1 = 405(0x195, float:5.68E-43) if (r0 == r1) goto L59 switch(r0) { case 300: goto L59; case 301: goto L59; case 302: goto L31; default: goto L30; } L30: goto L58 L31: java.lang.String r0 = "Expires" java.lang.String r0 = r3.header(r0) if (r0 != 0) goto L59 okhttp3.repackaged.CacheControl r0 = r3.cacheControl() int r0 = r0.maxAgeSeconds() r1 = -1 if (r0 != r1) goto L59 okhttp3.repackaged.CacheControl r0 = r3.cacheControl() boolean r0 = r0.isPublic() if (r0 != 0) goto L59 okhttp3.repackaged.CacheControl r0 = r3.cacheControl() boolean r0 = r0.isPrivate() if (r0 != 0) goto L59 L58: return r2 L59: okhttp3.repackaged.CacheControl r3 = r3.cacheControl() boolean r3 = r3.noStore() if (r3 != 0) goto L6e okhttp3.repackaged.CacheControl r3 = r4.cacheControl() boolean r3 = r3.noStore() if (r3 != 0) goto L6e r2 = 1 L6e: return r2 */ throw new UnsupportedOperationException("Method not decompiled: okhttp3.repackaged.internal.http.CacheStrategy.isCacheable(okhttp3.repackaged.Response, okhttp3.repackaged.Request):boolean"); } /* loaded from: classes6.dex */ public static class Factory { final Request aix; private Date alr; private String als; private Date alt; private String alu; private Date alv; private long alw; private long alx; private String aly; private int alz; final Response cacheResponse; final long nowMillis; public Factory(long j, Request request, Response response) { this.alz = -1; this.nowMillis = j; this.aix = request; this.cacheResponse = response; if (response != null) { Headers headers = response.headers(); int size = headers.size(); for (int i = 0; i < size; i++) { String name = headers.name(i); String value = headers.value(i); if (HttpHeaders.DATE.equalsIgnoreCase(name)) { this.alr = HttpDate.parse(value); this.als = value; } else if (HttpHeaders.EXPIRES.equalsIgnoreCase(name)) { this.alv = HttpDate.parse(value); } else if (HttpHeaders.LAST_MODIFIED.equalsIgnoreCase(name)) { this.alt = HttpDate.parse(value); this.alu = value; } else if (HttpHeaders.ETAG.equalsIgnoreCase(name)) { this.aly = value; } else if (HttpHeaders.AGE.equalsIgnoreCase(name)) { this.alz = HeaderParser.parseSeconds(value, -1); } else if (OkHeaders.SENT_MILLIS.equalsIgnoreCase(name)) { this.alw = Long.parseLong(value); } else if (OkHeaders.RECEIVED_MILLIS.equalsIgnoreCase(name)) { this.alx = Long.parseLong(value); } } } } /* JADX WARN: Multi-variable type inference failed */ public CacheStrategy get() { CacheStrategy uT = uT(); if (uT.networkRequest == null || !this.aix.cacheControl().onlyIfCached()) { return uT; } return new CacheStrategy(null, 0 == true ? 1 : 0); } /* JADX WARN: Multi-variable type inference failed */ private CacheStrategy uT() { Response response = null; Object[] objArr = 0; Object[] objArr2 = 0; Object[] objArr3 = 0; Object[] objArr4 = 0; Object[] objArr5 = 0; Object[] objArr6 = 0; Object[] objArr7 = 0; Object[] objArr8 = 0; Object[] objArr9 = 0; Object[] objArr10 = 0; Object[] objArr11 = 0; Object[] objArr12 = 0; if (this.cacheResponse == null) { return new CacheStrategy(this.aix, response); } if (this.aix.isHttps() && this.cacheResponse.handshake() == null) { return new CacheStrategy(this.aix, objArr11 == true ? 1 : 0); } if (!CacheStrategy.isCacheable(this.cacheResponse, this.aix)) { return new CacheStrategy(this.aix, objArr9 == true ? 1 : 0); } CacheControl cacheControl = this.aix.cacheControl(); if (cacheControl.noCache() || g(this.aix)) { return new CacheStrategy(this.aix, objArr2 == true ? 1 : 0); } long uV = uV(); long uU = uU(); if (cacheControl.maxAgeSeconds() != -1) { uU = Math.min(uU, TimeUnit.SECONDS.toMillis(cacheControl.maxAgeSeconds())); } long j = 0; long millis = cacheControl.minFreshSeconds() != -1 ? TimeUnit.SECONDS.toMillis(cacheControl.minFreshSeconds()) : 0L; CacheControl cacheControl2 = this.cacheResponse.cacheControl(); if (!cacheControl2.mustRevalidate() && cacheControl.maxStaleSeconds() != -1) { j = TimeUnit.SECONDS.toMillis(cacheControl.maxStaleSeconds()); } if (!cacheControl2.noCache()) { long j2 = millis + uV; if (j2 < j + uU) { Response.Builder newBuilder = this.cacheResponse.newBuilder(); if (j2 >= uU) { newBuilder.addHeader(HttpHeaders.WARNING, "110 HttpURLConnection \"Response is stale\""); } if (uV > 86400000 && uW()) { newBuilder.addHeader(HttpHeaders.WARNING, "113 HttpURLConnection \"Heuristic expiration\""); } return new CacheStrategy(objArr7 == true ? 1 : 0, newBuilder.build()); } } Request.Builder newBuilder2 = this.aix.newBuilder(); String str = this.aly; if (str != null) { newBuilder2.header(HttpHeaders.IF_NONE_MATCH, str); } else if (this.alt != null) { newBuilder2.header(HttpHeaders.IF_MODIFIED_SINCE, this.alu); } else if (this.alr != null) { newBuilder2.header(HttpHeaders.IF_MODIFIED_SINCE, this.als); } Request build = newBuilder2.build(); return g(build) ? new CacheStrategy(build, this.cacheResponse) : new CacheStrategy(build, objArr4 == true ? 1 : 0); } private long uU() { if (this.cacheResponse.cacheControl().maxAgeSeconds() != -1) { return TimeUnit.SECONDS.toMillis(r0.maxAgeSeconds()); } if (this.alv != null) { Date date = this.alr; long time = this.alv.getTime() - (date != null ? date.getTime() : this.alx); if (time > 0) { return time; } return 0L; } if (this.alt == null || this.cacheResponse.request().url().query() != null) { return 0L; } Date date2 = this.alr; long time2 = (date2 != null ? date2.getTime() : this.alw) - this.alt.getTime(); if (time2 > 0) { return time2 / 10; } return 0L; } private long uV() { Date date = this.alr; long max = date != null ? Math.max(0L, this.alx - date.getTime()) : 0L; if (this.alz != -1) { max = Math.max(max, TimeUnit.SECONDS.toMillis(this.alz)); } long j = this.alx; return max + (j - this.alw) + (this.nowMillis - j); } private boolean uW() { return this.cacheResponse.cacheControl().maxAgeSeconds() == -1 && this.alv == null; } private static boolean g(Request request) { return (request.header(HttpHeaders.IF_MODIFIED_SINCE) == null && request.header(HttpHeaders.IF_NONE_MATCH) == null) ? false : true; } } }