Files
rr3-apk/decompiled-community/sources/okhttp3/internal/cache/CacheStrategy.java
Daniel Elliott c080f0d97f Add Discord community version (64-bit only)
- Added realracing3-community.apk (71.57 MB)
- Removed 32-bit support (armeabi-v7a)
- Only includes arm64-v8a libraries
- Decompiled source code included
- Added README-community.md with analysis
2026-02-18 15:48:36 -08:00

247 lines
10 KiB
Java

package okhttp3.internal.cache;
import com.mbridge.msdk.foundation.download.Command;
import com.vungle.ads.internal.signals.SignalManager;
import java.util.Date;
import java.util.concurrent.TimeUnit;
import okhttp3.CacheControl;
import okhttp3.Headers;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.internal.Internal;
import okhttp3.internal.http.HttpDate;
import okhttp3.internal.http.HttpHeaders;
import org.apache.http.protocol.HTTP;
/* loaded from: classes5.dex */
public final class CacheStrategy {
public final Response cacheResponse;
public final Request networkRequest;
public 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 L33;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
public static boolean isCacheable(okhttp3.Response r3, okhttp3.Request r4) {
/*
int r0 = r3.code()
r1 = 200(0xc8, float:2.8E-43)
r2 = 0
if (r0 == r1) goto L5a
r1 = 410(0x19a, float:5.75E-43)
if (r0 == r1) goto L5a
r1 = 414(0x19e, float:5.8E-43)
if (r0 == r1) goto L5a
r1 = 501(0x1f5, float:7.02E-43)
if (r0 == r1) goto L5a
r1 = 203(0xcb, float:2.84E-43)
if (r0 == r1) goto L5a
r1 = 204(0xcc, float:2.86E-43)
if (r0 == r1) goto L5a
r1 = 307(0x133, float:4.3E-43)
if (r0 == r1) goto L31
r1 = 308(0x134, float:4.32E-43)
if (r0 == r1) goto L5a
r1 = 404(0x194, float:5.66E-43)
if (r0 == r1) goto L5a
r1 = 405(0x195, float:5.68E-43)
if (r0 == r1) goto L5a
switch(r0) {
case 300: goto L5a;
case 301: goto L5a;
case 302: goto L31;
default: goto L30;
}
L30:
goto L59
L31:
java.lang.String r0 = "Expires"
java.lang.String r0 = r3.header(r0)
if (r0 != 0) goto L5a
okhttp3.CacheControl r0 = r3.cacheControl()
int r0 = r0.maxAgeSeconds()
r1 = -1
if (r0 != r1) goto L5a
okhttp3.CacheControl r0 = r3.cacheControl()
boolean r0 = r0.isPublic()
if (r0 != 0) goto L5a
okhttp3.CacheControl r0 = r3.cacheControl()
boolean r0 = r0.isPrivate()
if (r0 == 0) goto L59
goto L5a
L59:
return r2
L5a:
okhttp3.CacheControl r3 = r3.cacheControl()
boolean r3 = r3.noStore()
if (r3 != 0) goto L6f
okhttp3.CacheControl r3 = r4.cacheControl()
boolean r3 = r3.noStore()
if (r3 != 0) goto L6f
r2 = 1
L6f:
return r2
*/
throw new UnsupportedOperationException("Method not decompiled: okhttp3.internal.cache.CacheStrategy.isCacheable(okhttp3.Response, okhttp3.Request):boolean");
}
public static class Factory {
public int ageSeconds;
public final Response cacheResponse;
public String etag;
public Date expires;
public Date lastModified;
public String lastModifiedString;
public final long nowMillis;
public long receivedResponseMillis;
public final Request request;
public long sentRequestMillis;
public Date servedDate;
public String servedDateString;
public Factory(long j, Request request, Response response) {
this.ageSeconds = -1;
this.nowMillis = j;
this.request = request;
this.cacheResponse = response;
if (response != null) {
this.sentRequestMillis = response.sentRequestAtMillis();
this.receivedResponseMillis = response.receivedResponseAtMillis();
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 (HTTP.DATE_HEADER.equalsIgnoreCase(name)) {
this.servedDate = HttpDate.parse(value);
this.servedDateString = value;
} else if ("Expires".equalsIgnoreCase(name)) {
this.expires = HttpDate.parse(value);
} else if ("Last-Modified".equalsIgnoreCase(name)) {
this.lastModified = HttpDate.parse(value);
this.lastModifiedString = value;
} else if (Command.HTTP_HEADER_ETAG.equalsIgnoreCase(name)) {
this.etag = value;
} else if ("Age".equalsIgnoreCase(name)) {
this.ageSeconds = HttpHeaders.parseSeconds(value, -1);
}
}
}
}
public CacheStrategy get() {
CacheStrategy candidate = getCandidate();
return (candidate.networkRequest == null || !this.request.cacheControl().onlyIfCached()) ? candidate : new CacheStrategy(null, null);
}
public final CacheStrategy getCandidate() {
String str;
if (this.cacheResponse == null) {
return new CacheStrategy(this.request, null);
}
if (this.request.isHttps() && this.cacheResponse.handshake() == null) {
return new CacheStrategy(this.request, null);
}
if (!CacheStrategy.isCacheable(this.cacheResponse, this.request)) {
return new CacheStrategy(this.request, null);
}
CacheControl cacheControl = this.request.cacheControl();
if (cacheControl.noCache() || hasConditions(this.request)) {
return new CacheStrategy(this.request, null);
}
CacheControl cacheControl2 = this.cacheResponse.cacheControl();
long cacheResponseAge = cacheResponseAge();
long computeFreshnessLifetime = computeFreshnessLifetime();
if (cacheControl.maxAgeSeconds() != -1) {
computeFreshnessLifetime = Math.min(computeFreshnessLifetime, TimeUnit.SECONDS.toMillis(cacheControl.maxAgeSeconds()));
}
long j = 0;
long millis = cacheControl.minFreshSeconds() != -1 ? TimeUnit.SECONDS.toMillis(cacheControl.minFreshSeconds()) : 0L;
if (!cacheControl2.mustRevalidate() && cacheControl.maxStaleSeconds() != -1) {
j = TimeUnit.SECONDS.toMillis(cacheControl.maxStaleSeconds());
}
if (!cacheControl2.noCache()) {
long j2 = millis + cacheResponseAge;
if (j2 < j + computeFreshnessLifetime) {
Response.Builder newBuilder = this.cacheResponse.newBuilder();
if (j2 >= computeFreshnessLifetime) {
newBuilder.addHeader("Warning", "110 HttpURLConnection \"Response is stale\"");
}
if (cacheResponseAge > SignalManager.TWENTY_FOUR_HOURS_MILLIS && isFreshnessLifetimeHeuristic()) {
newBuilder.addHeader("Warning", "113 HttpURLConnection \"Heuristic expiration\"");
}
return new CacheStrategy(null, newBuilder.build());
}
}
String str2 = this.etag;
if (str2 != null) {
str = "If-None-Match";
} else {
if (this.lastModified != null) {
str2 = this.lastModifiedString;
} else {
if (this.servedDate == null) {
return new CacheStrategy(this.request, null);
}
str2 = this.servedDateString;
}
str = "If-Modified-Since";
}
Headers.Builder newBuilder2 = this.request.headers().newBuilder();
Internal.instance.addLenient(newBuilder2, str, str2);
return new CacheStrategy(this.request.newBuilder().headers(newBuilder2.build()).build(), this.cacheResponse);
}
public final long computeFreshnessLifetime() {
if (this.cacheResponse.cacheControl().maxAgeSeconds() != -1) {
return TimeUnit.SECONDS.toMillis(r0.maxAgeSeconds());
}
if (this.expires != null) {
Date date = this.servedDate;
long time = this.expires.getTime() - (date != null ? date.getTime() : this.receivedResponseMillis);
if (time > 0) {
return time;
}
return 0L;
}
if (this.lastModified == null || this.cacheResponse.request().url().query() != null) {
return 0L;
}
Date date2 = this.servedDate;
long time2 = (date2 != null ? date2.getTime() : this.sentRequestMillis) - this.lastModified.getTime();
if (time2 > 0) {
return time2 / 10;
}
return 0L;
}
public final long cacheResponseAge() {
Date date = this.servedDate;
long max = date != null ? Math.max(0L, this.receivedResponseMillis - date.getTime()) : 0L;
int i = this.ageSeconds;
if (i != -1) {
max = Math.max(max, TimeUnit.SECONDS.toMillis(i));
}
long j = this.receivedResponseMillis;
return max + (j - this.sentRequestMillis) + (this.nowMillis - j);
}
public final boolean isFreshnessLifetimeHeuristic() {
return this.cacheResponse.cacheControl().maxAgeSeconds() == -1 && this.expires == null;
}
public static boolean hasConditions(Request request) {
return (request.header("If-Modified-Since") == null && request.header("If-None-Match") == null) ? false : true;
}
}
}