undici icon indicating copy to clipboard operation
undici copied to clipboard

fix: max-age=0 and no-cache must be considered "immediately stale"

Open steunix opened this issue 3 months ago • 3 comments

This relates to...

https://github.com/nodejs/undici/discussions/4620#discussioncomment-14685096

Rationale

When server is responding with a max-age=0 or no-cache, Undici does not cache the response and subsequent requests do not include if-none-match or if-modified-since headers.

Changes

The function determineStaleAt does not take max-age=0 and no-cache into account, returning undefined in both cases: the caller will ignore the response in regard to the cache handling

Features

N/A

Bug Fixes

N/A

Breaking Changes and Deprecations

N/A

Status

  • [x] I have read and agreed to the Developer's Certificate of Origin
  • [x] Tested
  • [ ] Benchmarked (optional)
  • [ ] Documented
  • [ ] Review ready
  • [ ] In review
  • [ ] Merge ready

steunix avatar Oct 15 '25 10:10 steunix

Can you add a test for it

Sorry but I don't know the code base enough to even guess at what level to put a test.

steunix avatar Oct 16 '25 07:10 steunix

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 92.92%. Comparing base (dc5802d) to head (cdb292c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4624      +/-   ##
==========================================
- Coverage   92.93%   92.92%   -0.01%     
==========================================
  Files         106      106              
  Lines       33092    33097       +5     
==========================================
+ Hits        30753    30756       +3     
- Misses       2339     2341       +2     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov-commenter avatar Oct 16 '25 12:10 codecov-commenter

You can put it within the interceptors tests for cache interceptor, attempting to just replicate the behavior described in the issue

metcoder95 avatar Oct 17 '25 08:10 metcoder95