- From: Sylvain Bellone <notifications@github.com>
- Date: Tue, 14 Feb 2023 05:48:45 -0800
- To: whatwg/fetch <fetch@noreply.github.com>
- Cc: Subscribed <subscribed@noreply.github.com>
- Message-ID: <whatwg/fetch/issues/1604@github.com>
### Context
I was testing conditional requests with the Node.js's implementation of fetch, and came across that behaviour:
When adding a conditional header to the request (`If-None-Match`), the following headers are automatically added:
- `Cache-Control: no-cache`
- `Pragma: no-cache`
This makes the reference Node.js server, Express, systematically return a `200` instead of a `304`.
The team rightly [redirected](https://github.com/nodejs/undici/issues/1930#issuecomment-1429598650) me to the spec, where I can indeed find this following behaviour described [here](https://fetch.spec.whatwg.org/#http-network-or-cache-fetch):
> 16. If httpRequest’s [cache mode](https://fetch.spec.whatwg.org/#concept-request-cache-mode) is "default" and httpRequest’s [header list](https://fetch.spec.whatwg.org/#concept-request-header-list) [contains](https://fetch.spec.whatwg.org/#header-list-contains) `If-Modified-Since`, `If-None-Match`, `If-Unmodified-Since`, `If-Match`, or `If-Range`, then set httpRequest’s [cache mode](https://fetch.spec.whatwg.org/#concept-request-cache-mode) to "no-store".
> 17. ...
> 18. If httpRequest’s [cache mode](https://fetch.spec.whatwg.org/#concept-request-cache-mode) is "no-store" or "reload", then:
- If httpRequest’s [header list](https://fetch.spec.whatwg.org/#concept-request-header-list) [does not contain](https://fetch.spec.whatwg.org/#header-list-contains) `Pragma`, then [append](https://fetch.spec.whatwg.org/#concept-header-list-append) (`Pragma`, `no-cache`) to httpRequest’s [header list](https://fetch.spec.whatwg.org/#concept-request-header-list).
- If httpRequest’s [header list](https://fetch.spec.whatwg.org/#concept-request-header-list) [does not contain](https://fetch.spec.whatwg.org/#header-list-contains) `Cache-Control`, then [append](https://fetch.spec.whatwg.org/#concept-header-list-append) (`Cache-Control`, `no-cache`) to httpRequest’s [header list](https://fetch.spec.whatwg.org/#concept-request-header-list).
### Question
As a developer perspective, it's counter intuitive to have some `no-cache` headers automatically added when the intention was to do a conditional request.
- Is it expected that developers systematically have to pass both Conditional and Cache-Control headers?
- If so, what `Cache-Control` value should we use?
- If not, what is the correct way to do conditional requests?
Thank you for any clarification you can bring.
--
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/fetch/issues/1604
You are receiving this because you are subscribed to this thread.
Message ID: <whatwg/fetch/issues/1604@github.com>
Received on Tuesday, 14 February 2023 13:48:57 UTC