content: package okhttp3.internal.cache;
  
  import androidx.constraintlayout.core.motion.utils.TypedValues;
  import java.util.Date;
  import java.util.concurrent.TimeUnit;
  import kotlin.Metadata;
  import kotlin.jvm.internal.DefaultConstructorMarker;
  import kotlin.jvm.internal.Intrinsics;
  import kotlin.text.StringsKt;
  import mt.Log1F380D;
  import okhttp3.CacheControl;
  import okhttp3.Headers;
  import okhttp3.Request;
  import okhttp3.Response;
  import okhttp3.internal.Util;
  import okhttp3.internal.http.DatesKt;
  
  @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u0018\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\b\u0018\u0000 \u000b2\u00020\u0001:\u0002\u000b\fB\u001b\b\u0000\u0012\b\u0010\u0002\u001a\u0004\u0018\u00010\u0003\u0012\b\u0010\u0004\u001a\u0004\u0018\u00010\u0005¢\u0006\u0002\u0010\u0006R\u0013\u0010\u0004\u001a\u0004\u0018\u00010\u0005¢\u0006\b\n\u0000\u001a\u0004\b\u0007\u0010\bR\u0013\u0010\u0002\u001a\u0004\u0018\u00010\u0003¢\u0006\b\n\u0000\u001a\u0004\b\t\u0010\n¨\u0006\r"}, d2 = {"Lokhttp3/internal/cache/CacheStrategy;", "", "networkRequest", "Lokhttp3/Request;", "cacheResponse", "Lokhttp3/Response;", "(Lokhttp3/Request;Lokhttp3/Response;)V", "getCacheResponse", "()Lokhttp3/Response;", "getNetworkRequest", "()Lokhttp3/Request;", "Companion", "Factory", "okhttp"}, k = 1, mv = {1, 4, 0})
  /* compiled from: CacheStrategy.kt */
  public final class CacheStrategy {
      public static final Companion Companion = new Companion((DefaultConstructorMarker) null);
      private final Response cacheResponse;
      private final Request networkRequest;
  
      @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u001e\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u000b\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\b\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\u0016\u0010\u0003\u001a\u00020\u00042\u0006\u0010\u0005\u001a\u00020\u00062\u0006\u0010\u0007\u001a\u00020\b¨\u0006\t"}, d2 = {"Lokhttp3/internal/cache/CacheStrategy$Companion;", "", "()V", "isCacheable", "", "response", "Lokhttp3/Response;", "request", "Lokhttp3/Request;", "okhttp"}, k = 1, mv = {1, 4, 0})
      /* compiled from: 01C5 */
      public static final class Companion {
          private Companion() {
          }
  
          public /* synthetic */ Companion(DefaultConstructorMarker $constructor_marker) {
              this();
          }
  
          public final boolean isCacheable(Response response, Request request) {
              Intrinsics.checkNotNullParameter(response, "response");
              Intrinsics.checkNotNullParameter(request, "request");
              switch (response.code()) {
                  case 200:
                  case 203:
                  case 204:
                  case 300:
                  case 301:
                  case 308:
                  case 404:
                  case 405:
                  case 410:
                  case 414:
                  case TypedValues.PositionType.TYPE_TRANSITION_EASING:
                      break;
                  case 302:
                  case 307:
                      String header$default = Response.header$default(response, "Expires", (String) null, 2, (Object) null);
                      Log1F380D.a((Object) header$default);
                      if (header$default == null && response.cacheControl().maxAgeSeconds() == -1 && !response.cacheControl().isPublic() && !response.cacheControl().isPrivate()) {
                          return false;
                      }
                  default:
                      return false;
              }
              return !response.cacheControl().noStore() && !request.cacheControl().noStore();
          }
      }
  
      @Metadata(bv = {1, 0, 3}, d1 = {"\u0000B\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0000\n\u0002\u0010\t\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\b\n\u0000\n\u0002\u0010\u000e\n\u0000\n\u0002\u0018\u0002\n\u0002\b\n\n\u0002\u0018\u0002\n\u0002\b\u0003\n\u0002\u0010\u000b\n\u0002\b\u0002\u0018\u00002\u00020\u0001B\u001f\u0012\u0006\u0010\u0002\u001a\u00020\u0003\u0012\u0006\u0010\u0004\u001a\u00020\u0005\u0012\b\u0010\u0006\u001a\u0004\u0018\u00010\u0007¢\u0006\u0002\u0010\bJ\b\u0010\u0017\u001a\u00020\u0003H\u0002J\u0006\u0010\u0018\u001a\u00020\u0019J\b\u0010\u001a\u001a\u00020\u0019H\u0002J\b\u0010\u001b\u001a\u00020\u0003H\u0002J\u0010\u0010\u001c\u001a\u00020\u001d2\u0006\u0010\u0004\u001a\u00020\u0005H\u0002J\b\u0010\u001e\u001a\u00020\u001dH\u0002R\u000e\u0010\t\u001a\u00020\nX\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0006\u001a\u0004\u0018\u00010\u0007X\u0004¢\u0006\u0002\n\u0000R\u0010\u0010\u000b\u001a\u0004\u0018\u00010\fX\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\r\u001a\u0004\u0018\u00010\u000eX\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u000f\u001a\u0004\u0018\u00010\u000eX\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0010\u001a\u0004\u0018\u00010\fX\u000e¢\u0006\u0002\n\u0000R\u000e\u0010\u0002\u001a\u00020\u0003X\u0004¢\u0006\u0002\n\u0000R\u000e\u0010\u0011\u001a\u00020\u0003X\u000e¢\u0006\u0002\n\u0000R\u0014\u0010\u0004\u001a\u00020\u0005X\u0004¢\u0006\b\n\u0000\u001a\u0004\b\u0012\u0010\u0013R\u000e\u0010\u0014\u001a\u00020\u0003X\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0015\u001a\u0004\u0018\u00010\u000eX\u000e¢\u0006\u0002\n\u0000R\u0010\u0010\u0016\u001a\u0004\u0018\u00010\fX\u000e¢\u0006\u0002\n\u0000¨\u0006\u001f"}, d2 = {"Lokhttp3/internal/cache/CacheStrategy$Factory;", "", "nowMillis", "", "request", "Lokhttp3/Request;", "cacheResponse", "Lokhttp3/Response;", "(JLokhttp3/Request;Lokhttp3/Response;)V", "ageSeconds", "", "etag", "", "expires", "Ljava/util/Date;", "lastModified", "lastModifiedString", "receivedResponseMillis", "getRequest$okhttp", "()Lokhttp3/Request;", "sentRequestMillis", "servedDate", "servedDateString", "cacheResponseAge", "compute", "Lokhttp3/internal/cache/CacheStrategy;", "computeCandidate", "computeFreshnessLifetime", "hasConditions", "", "isFreshnessLifetimeHeuristic", "okhttp"}, k = 1, mv = {1, 4, 0})
      /* compiled from: CacheStrategy.kt */
      public static final class Factory {
          private int ageSeconds = -1;
          private final Response cacheResponse;
          private String etag;
          private Date expires;
          private Date lastModified;
          private String lastModifiedString;
          private final long nowMillis;
          private long receivedResponseMillis;
          private final Request request;
          private long sentRequestMillis;
          private Date servedDate;
          private String servedDateString;
  
          public Factory(long nowMillis2, Request request2, Response cacheResponse2) {
              Intrinsics.checkNotNullParameter(request2, "request");
              this.nowMillis = nowMillis2;
              this.request = request2;
              this.cacheResponse = cacheResponse2;
              if (cacheResponse2 != null) {
                  this.sentRequestMillis = cacheResponse2.sentRequestAtMillis();
                  this.receivedResponseMillis = cacheResponse2.receivedResponseAtMillis();
                  Headers headers = cacheResponse2.headers();
                  int size = headers.size();
                  for (int i = 0; i < size; i++) {
                      String name = headers.name(i);
                      String value = headers.value(i);
                      if (StringsKt.equals(name, "Date", true)) {
                          this.servedDate = DatesKt.toHttpDateOrNull(value);
                          this.servedDateString = value;
                      } else if (StringsKt.equals(name, "Expires", true)) {
                          this.expires = DatesKt.toHttpDateOrNull(value);
                      } else if (StringsKt.equals(name, "Last-Modified", true)) {
                          this.lastModified = DatesKt.toHttpDateOrNull(value);
                          this.lastModifiedString = value;
                      } else if (StringsKt.equals(name, "ETag", true)) {
                          this.etag = value;
                      } else if (StringsKt.equals(name, "Age", true)) {
                          this.ageSeconds = Util.toNonNegativeInt(value, -1);
                      }
                  }
              }
          }
  
          private final long cacheResponseAge() {
              Date date = this.servedDate;
              long j = 0;
              if (date != null) {
                  j = Math.max(0, this.receivedResponseMillis - date.getTime());
              }
              long max = this.ageSeconds != -1 ? Math.max(j, TimeUnit.SECONDS.toMillis((long) this.ageSeconds)) : j;
              long j2 = this.receivedResponseMillis;
              return max + (j2 - this.sentRequestMillis) + (this.nowMillis - j2);
          }
  
          private final CacheStrategy computeCandidate() {
              String str;
              String str2;
              if (this.cacheResponse == null) {
                  return new CacheStrategy(this.request, (Response) null);
              }
              if (this.request.isHttps() && this.cacheResponse.handshake() == null) {
                  return new CacheStrategy(this.request, (Response) null);
              }
              if (!CacheStrategy.Companion.isCacheable(this.cacheResponse, this.request)) {
                  return new CacheStrategy(this.request, (Response) null);
              }
              CacheControl cacheControl = this.request.cacheControl();
              if (cacheControl.noCache()) {
                  CacheControl cacheControl2 = cacheControl;
              } else if (hasConditions(this.request)) {
                  CacheControl cacheControl3 = cacheControl;
              } else {
                  CacheControl cacheControl4 = this.cacheResponse.cacheControl();
                  long cacheResponseAge = cacheResponseAge();
                  long computeFreshnessLifetime = computeFreshnessLifetime();
                  if (cacheControl.maxAgeSeconds() != -1) {
                      computeFreshnessLifetime = Math.min(computeFreshnessLifetime, TimeUnit.SECONDS.toMillis((long) cacheControl.maxAgeSeconds()));
                  }
                  long j = 0;
                  if (cacheControl.minFreshSeconds() != -1) {
                      j = TimeUnit.SECONDS.toMillis((long) cacheControl.minFreshSeconds());
                  }
                  long j2 = 0;
                  if (!cacheControl4.mustRevalidate() && cacheControl.maxStaleSeconds() != -1) {
                      j2 = TimeUnit.SECONDS.toMillis((long) cacheControl.maxStaleSeconds());
                  }
                  if (cacheControl4.noCache() || cacheResponseAge + j >= computeFreshnessLifetime + j2) {
                      if (this.etag != null) {
                          str2 = "If-None-Match";
                          str = this.etag;
                      } else if (this.lastModified != null) {
                          str2 = "If-Modified-Since";
                          str = this.lastModifiedString;
                      } else if (this.servedDate != null) {
                          str2 = "If-Modified-Since";
                          str = this.servedDateString;
                      } else {
                          CacheControl cacheControl5 = cacheControl;
                          return new CacheStrategy(this.request, (Response) null);
                      }
                      Headers.Builder newBuilder = this.request.headers().newBuilder();
                      Intrinsics.checkNotNull(str);
                      newBuilder.addLenient$okhttp(str2, str);
                      CacheControl cacheControl6 = cacheControl;
                      return new CacheStrategy(this.request.newBuilder().headers(newBuilder.build()).build(), this.cacheResponse);
                  }
                  Response.Builder newBuilder2 = this.cacheResponse.newBuilder();
                  if (cacheResponseAge + j >= computeFreshnessLifetime) {
                      newBuilder2.addHeader("Warning", "110 HttpURLConnection \"Response is stale\"");
                  }
                  if (cacheResponseAge > 86400000 && isFreshnessLifetimeHeuristic()) {
                      newBuilder2.addHeader("Warning", "113 HttpURLConnection \"Heuristic expiration\"");
                  }
                  return new CacheStrategy((Request) null, newBuilder2.build());
              }
              return new CacheStrategy(this.request, (Response) null);
          }
  
          private final long computeFreshnessLifetime() {
              Response response = this.cacheResponse;
              Intrinsics.checkNotNull(response);
              CacheControl cacheControl = response.cacheControl();
              if (cacheControl.maxAgeSeconds() != -1) {
                  return TimeUnit.SECONDS.toMillis((long) cacheControl.maxAgeSeconds());
              }
              Date date = this.expires;
              if (date != null) {
                  Date date2 = this.servedDate;
                  long time = date.getTime() - (date2 != null ? date2.getTime() : this.receivedResponseMillis);
                  if (time > 0) {
                      return time;
                  }
                  return 0;
              } else if (this.lastModified == null || this.cacheResponse.request().url().query() != null) {
                  return 0;
              } else {
                  Date date3 = this.servedDate;
                  long time2 = date3 != null ? date3.getTime() : this.sentRequestMillis;
                  Date date4 = this.lastModified;
                  Intrinsics.checkNotNull(date4);
                  long time3 = time2 - date4.getTime();
                  if (time3 > 0) {
                      return time3 / ((long) 10);
                  }
                  return 0;
              }
          }
  
          private final boolean hasConditions(Request request2) {
              return (request2.header("If-Modified-Since") == null && request2.header("If-None-Match") == null) ? false : true;
          }
  
          private final boolean isFreshnessLifetimeHeuristic() {
              Response response = this.cacheResponse;
              Intrinsics.checkNotNull(response);
              return response.cacheControl().maxAgeSeconds() == -1 && this.expires == null;
          }
  
          public final CacheStrategy compute() {
              CacheStrategy computeCandidate = computeCandidate();
              return (computeCandidate.getNetworkRequest() == null || !this.request.cacheControl().onlyIfCached()) ? computeCandidate : new CacheStrategy((Request) null, (Response) null);
          }
  
          public final Request getRequest$okhttp() {
              return this.request;
          }
      }
  
      public CacheStrategy(Request networkRequest2, Response cacheResponse2) {
          this.networkRequest = networkRequest2;
          this.cacheResponse = cacheResponse2;
      }
  
      public final Response getCacheResponse() {
          return this.cacheResponse;
      }
  
      public final Request getNetworkRequest() {
          return this.networkRequest;
      }
  }
  