-
Notifications
You must be signed in to change notification settings - Fork 36
Open
Labels
Needs Triageneeds an initial reviewneeds an initial review
Description
Is there an existing issue for this?
- I have searched the existing issues
Current Behavior
A response that returns an empty body (for example, a HEAD
request) does not write a cache entry.
Expected Behavior
An empty response body should be written to the cache. (HEAD
is useful when looking for redirected responses, for example, but I think it's legitimate to cache empty responses to GET
and potentially other verbs.)
Steps To Reproduce
- In Node.js
- With a default make-fetch-happen instance (i.e. no
.defaults()
) - Run this:
import mfh from 'make-fetch-happen';
const res = await mfh('https://www.google.com/', { method: 'HEAD', cachePath: './cache' });
await res.text(); // "Requests will not be cached unless their response bodies are consumed."
console.log(res.headers.get('x-local-cache-status'));
- Observe that the
x-local-cache-status
header is set toskip
, and./cache/
hasn't been created. - Change
HEAD
toGET
and observe thatx-local-cache-status
ismiss
and./cache
is created and populated.
Environment
- npm: 10.5.0
- Node: v20.12.2
- OS: Fedora 39
- platform: Linux x86_64
Metadata
Metadata
Assignees
Labels
Needs Triageneeds an initial reviewneeds an initial review