Closed swankjesse closed 7 years ago
In the section 2 of the RFC8264, it says that if a response is immutable, a reload should ignore a conditional request, but a force reload should not.
Clients SHOULD NOT issue a conditional request during the response's freshness lifetime (e.g., upon a reload) unless explicitly overridden by the user (e.g., a force reload).
And then I found that in Chrome, a force reload, pressing Ctrl + F5, is a request that contains a Cache-Control: no-cache header while a common reload, simply pressing F5, is a request that contains condition headers. So I guess the code below indicates a reload and a force reload, if it is the same meaning with Chrome. Both of them will perform a request from network no matter the response is immutable or not.
CacheControl requestCaching = request.cacheControl();
if (requestCaching.noCache() || hasConditions(request)) {
return new CacheStrategy(request, null);
}
CacheControl responseCaching = cacheResponse.cacheControl();
if (responseCaching.immutable()) {
return new CacheStrategy(null, cacheResponse);
}
Does that contradicts with the RFC? Plus, OkHttp doesn't compute the freshness lifttime before checking whether the response is immutable, are there other considerations?
@ lxd1047926543 is this a bug report? Could you open a new issue with a failing test?
@swankjesse I haven't encountered a failure, I'm just confused by the difference among OkHttp implementation and the RFC and the other implementations such as Firefox. Firefox implements the Cache-Control: immutable directive, it doesn't issue an conditional request if the cached response is immutable when reloading (F5), but do issue a Cache-Control: no-cache request if the cached response is immutable when forcefully reloading (Ctrl+F5). Thanks for your time.
There's no such thing as forceful reloading in OkHttp. The closest we have is making a request without the cache.
@lxd1047926543 @swankjesse I have experienced this in the library recently and what we have seen is that as soon as the immutable extension exists, the cached response is always used regardless of the max-age value. Now I'm not an expert on how these headers should be respected but please see my pull request for how I interpret they should work. https://github.com/square/okhttp/pull/4312
I have opened issue #4313 to capture the bug
https://bitsup.blogspot.ca/2016/05/cache-control-immutable.html?m=1