Fixed must-revalidate on the request side for now as per details in #1406.
This commit is contained in:
Christopher Jenkins
2019-10-21 12:03:19 -10:00
committed by Leonid Stashevsky
parent 1b4ab0adf6
commit 63dbc88040

View File

@@ -87,9 +87,13 @@ internal fun HttpResponse.cacheExpires(): GMTDate {
@KtorExperimentalAPI
internal fun HttpCacheEntry.shouldValidate(): Boolean {
val cacheControl = responseHeaders[HttpHeaders.CacheControl]?.let { parseHeaderValue(it) } ?: emptyList()
var result = GMTDate() > expires
result = result || CacheControl.MUST_REVALIDATE in cacheControl
result = result || CacheControl.NO_CACHE in cacheControl
return result
val isStale = GMTDate() > expires
// must-revalidate; re-validate once STALE, and MUST NOT return a cached response once stale.
// This is how majority of clients implement the RFC
// OkHttp Implements this the same: https://github.com/square/okhttp/issues/4043#issuecomment-403679369
// Disabled for now, as we don't currently return a cached object when there's a network failure; must-revalidate
// works the same as being stale on the request side. On response side, must-revalidate would not return a cached
// object if we are stale and couldn't refresh.
// isStale = isStale && CacheControl.MUST_REVALIDATE in cacheControl
return isStale || CacheControl.NO_CACHE in cacheControl
}