Skip to content

fix: match Cache-Control no-cache directive case-insensitively#79

Open
spokodev wants to merge 1 commit into
jshttp:masterfrom
spokodev:fix/inm-parse
Open

fix: match Cache-Control no-cache directive case-insensitively#79
spokodev wants to merge 1 commit into
jshttp:masterfrom
spokodev:fix/inm-parse

Conversation

@spokodev

@spokodev spokodev commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Cache-Control directive names are case-insensitive tokens (RFC 9111 §5.2, previously RFC 7234 §5.2), but CACHE_CONTROL_NO_CACHE_REGEXP only matches the lowercase spelling. A request that sends Cache-Control: No-Cache (or any other casing) is not detected as no-cache, so fresh() can return true and the caller answers an explicit end-to-end reload with a stale 304 instead of revalidating.

Repro:

fresh(
  { 'cache-control': 'No-Cache', 'if-none-match': '"foo"' },
  { etag: '"foo"' }
)
// => true   (expected false: no-cache must force a stale result)

The fix adds the i flag to the existing regexp, keeping the (?:^|,) / (?:,|$) boundaries so it still only matches the standalone directive and not substrings like x-no-cache. Adds a regression test.

Cache directive names are case-insensitive tokens (RFC 9111 Section 5.2),
but the no-cache detection regexp only matched the lowercase spelling, so a
request with Cache-Control: No-Cache was treated as cacheable and could be
answered with a stale 304 instead of forcing an end-to-end reload.
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