[whatwg/fetch] Cache-mode and upstream Cache-Control (#722)

[HTTP-network-or-cache-fetch](https://fetch.spec.whatwg.org/#http-network-or-cache-fetch) says:

> 12. If httpRequest’s cache mode is "default" and httpRequest’s header list contains `If-Modified-Since`, `If-None-Match`, `If-Unmodified-Since`, `If-Match`, or `If-Range`, then set httpRequest’s cache mode to "no-store".

The following text was added to fix #201, #231 and #232 (AFAICT):

> 13. If httpRequest’s cache mode is "no-cache" and httpRequest’s header list does not contain `Cache-Control`, then append `Cache-Control`/`max-age=0` to httpRequest’s header list.
>
> 14. If httpRequest’s cache mode is "no-store" or "reload", then:
> 
> >  1. If httpRequest’s header list does not contain `Pragma`, then append `Pragma`/`no-cache` to httpRequest’s header list.
> >
> >  2. If httpRequest’s header list does not contain `Cache-Control`, then append `Cache-Control`/`no-cache` to httpRequest’s header list.

This means that in several situations when the developer is trying to influence the local cache behaviour, it triggers request `Pragma` and `Cache-Control` headers that effectively disable upstream caches, even though this might not be desired.

In particular, setting `If-Modified-Since`, `If-None-Match` and other validating headers doesn't need to disable upstream caches; it's an entirely reasonable expectation for the upstream cache to be able to serve the request as normal. As specified, this is only an incentive for upstream caches to ignore these request directives, which isn't good for interop.

Even without validation, a developer might wish to bypass the browser cache with `no-store` but still use upstream caches (perhaps because they have a reliable out-of-band way to invalidate those caches, e.g., in a CDN).

I think the best solution here would be to remove (13) and (14), or to provide a separate control over these behaviours (e.g., an init flag to turn it off), so that developers have as much flexibility as they need; as specified, fetch() is making a decision for them. 

If not, at a minimum the [documentation for cache mode](https://fetch.spec.whatwg.org/#concept-request-cache-mode) needs to be updated to indicate that it is intended to influence not only the local cache, but also upstream caches.

P.S. I've tested to see if these headers are actually added, by making `no-store` requests. From what I can see:

* Chrome doesn't append `Pragma: no-cache` or `Cache-Control: no-cache`
* Firefox only appends `Pragma: no-cache`, and ignores the "If httpRequest's header list does not contain `Pragma`" condition (i.e, it appends it even if `Pragma` is present)
* Safari appends both if they aren't already present

-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/722

Received on Friday, 11 May 2018 08:18:41 UTC