Skip to content

fix(storage/http): preserve explicit zero maxAge - #329

Open
lprnmns wants to merge 1 commit into
unjs:mainfrom
lprnmns:fix/http-max-age-zero
Open

fix(storage/http): preserve explicit zero maxAge#329
lprnmns wants to merge 1 commit into
unjs:mainfrom
lprnmns:fix/http-max-age-zero

Conversation

@lprnmns

@lprnmns lprnmns commented Aug 31, 2026

Copy link
Copy Markdown

Problem

When an HTTP source response has no cache-control header, ipxHttpStorage({ maxAge: 0 }) was coerced to the default 300 seconds by falsy-value fallback. Deployments intending to disable caching therefore received the wrong cache duration.

Fix

Use nullish fallback for the HTTP storage default so an explicit zero is preserved. The option documentation now records that zero disables caching.

Tests

  • pnpm vitest test/storage/http.test.ts -t 'preserves an explicit zero maxAge' — failed before the fix with 300, passed after the fix
  • pnpm vitest test/storage/http.test.ts --run — passed, 90 tests
  • pnpm build — passed
  • pnpm test — passed, 453 tests and 9 skipped
  • git diff HEAD^ HEAD --check — passed

Compatibility

Only an explicit maxAge: 0 changes. Nonzero options, environment fallback, and upstream cache-control handling are unchanged; no API or dependency changes are introduced.

Related issue

Independent reproduction; no matching open issue was found. Historical cache-control issues #166 and #179 concern different, closed behavior.

Summary by CodeRabbit

  • Bug Fixes

    • Honor an explicitly configured cache duration of 0, disabling caching instead of applying the default duration.
    • Preserve zero-valued cache settings when responses do not include cache-control headers.
  • Documentation

    • Clarified that setting the cache duration to 0 disables caching.

@coderabbitai

coderabbitai Bot commented Aug 31, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: f2d2f75f-dfa6-4164-a936-d0bdedc69dcd

📥 Commits

Reviewing files that changed from the base of the PR and between de8b0ab and bffa360.

📒 Files selected for processing (2)
  • src/storage/http.ts
  • test/storage/http.test.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

The HTTP storage now preserves an explicit maxAge of 0 instead of applying the default. The option documentation describes this behavior, and a getMeta test verifies it when the response has no cache-control header.

Changes

HTTP cache age handling

Layer / File(s) Summary
Preserve and validate zero maxAge
src/storage/http.ts, test/storage/http.test.ts
The default cache age uses nullish coalescing, and the option documentation defines 0 as disabling caching. The getMeta test verifies that maxAge: 0 is preserved.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Merge Risk: ⚪ Minimal · up to bffa3

This localized change preserves an explicitly configured zero cache duration without affecting other maxAge or cache-control behavior; no actionable merge-blocking risk remains after normal checks and review.

Suggested reviewers: pi0

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: preserving an explicitly configured zero maxAge in HTTP storage.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@lprnmns
lprnmns marked this pull request as ready for review August 31, 2026 11:43
@lprnmns
lprnmns requested a review from pi0 as a code owner August 31, 2026 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant