Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Empty response body is not cached #293

Open
1 task done
peterjanes opened this issue Apr 17, 2024 · 0 comments
Open
1 task done

[BUG] Empty response body is not cached #293

peterjanes opened this issue Apr 17, 2024 · 0 comments
Labels
Needs Triage needs an initial review

Comments

@peterjanes
Copy link

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

  1. In Node.js
  2. With a default make-fetch-happen instance (i.e. no .defaults())
  3. 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'));
  1. Observe that the x-local-cache-status header is set to skip, and ./cache/ hasn't been created.
  2. Change HEAD to GET and observe that x-local-cache-status is miss and ./cache is created and populated.

Environment

  • npm: 10.5.0
  • Node: v20.12.2
  • OS: Fedora 39
  • platform: Linux x86_64
@peterjanes peterjanes added the Needs Triage needs an initial review label Apr 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Triage needs an initial review
Projects
None yet
Development

No branches or pull requests

1 participant