Skip to content

cache-control: no-cache: use quoted-string form#4177

Merged
Uzlopak merged 3 commits into
nodejs:mainfrom
alxndrsn:no-cache-quoted-string-form
Aug 13, 2025
Merged

cache-control: no-cache: use quoted-string form#4177
Uzlopak merged 3 commits into
nodejs:mainfrom
alxndrsn:no-cache-quoted-string-form

Conversation

@alxndrsn

@alxndrsn alxndrsn commented Apr 23, 2025

Copy link
Copy Markdown
Contributor

Update comment example of qualified no-cache directives (no-cache=...) to use the quoted-string form instead of the token form.

Per https://datatracker.ietf.org/doc/html/rfc9111#name-no-cache-2:

This directive uses the quoted-string form of the argument syntax. A sender SHOULD NOT generate the token form (even if quoting appears not to be needed for single-entry lists).

This relates to...

cache-control response header's qualified no-cache directive.

Rationale

Seems more correct to follow spec recommendations in documentation.

Support for token form seems to be deliberate:

test('no-cache with headers', () => {
let directives = parseCacheControlHeader('max-age=10, no-cache=some-header, only-if-cached')
deepStrictEqual(directives, {
'max-age': 10,
'no-cache': [
'some-header'
],
'only-if-cached': true
})
directives = parseCacheControlHeader('max-age=10, no-cache="some-header", only-if-cached')
deepStrictEqual(directives, {
'max-age': 10,
'no-cache': [
'some-header'
],
'only-if-cached': true
})
directives = parseCacheControlHeader('max-age=10, no-cache="some-header, another-one", only-if-cached')
deepStrictEqual(directives, {
'max-age': 10,
'no-cache': [
'some-header',
'another-one'
],
'only-if-cached': true
})
})

Changes

Update comment and test examples of qualified no-cache directives (no-cache=...) to use the quoted-string form instead of the token form.

Features

N/A

Bug Fixes

N/A

Breaking Changes and Deprecations

Should not break anything, as no code changed.

Status

alxndrsn added 3 commits April 23, 2025 05:13
Update comment and test examples of qualified no-cache directives (no-cache=...) to use the quoted-string form instead of the token form.

Per https://httpwg.org/specs/rfc9111.html#cache-response-directive.no-cache:

> This directive uses the quoted-string form of the argument syntax. A sender SHOULD NOT generate the token form (even if quoting appears not to be needed for single-entry lists).
@alxndrsn

Copy link
Copy Markdown
Contributor Author

The no-cache=... parsing code seems to go out of its way to support various different token or mixed token/quoted-string formats:

test('no-cache with headers', () => {
let directives = parseCacheControlHeader('max-age=10, no-cache=some-header, only-if-cached')
deepStrictEqual(directives, {
'max-age': 10,
'no-cache': [
'some-header'
],
'only-if-cached': true
})
directives = parseCacheControlHeader('max-age=10, no-cache="some-header", only-if-cached')
deepStrictEqual(directives, {
'max-age': 10,
'no-cache': [
'some-header'
],
'only-if-cached': true
})
directives = parseCacheControlHeader('max-age=10, no-cache="some-header, another-one", only-if-cached')
deepStrictEqual(directives, {
'max-age': 10,
'no-cache': [
'some-header',
'another-one'
],
'only-if-cached': true
})
})

Would it be better to only allow quote-string format?

@alxndrsn alxndrsn marked this pull request as ready for review April 23, 2025 05:45
@mcollina

Copy link
Copy Markdown
Member

Would it be better to only allow quote-string format?

@flakey5 was this due to the compatibility tests?

@flakey5

flakey5 commented Apr 23, 2025

Copy link
Copy Markdown
Member

@flakey5 was this due to the compatibility tests?

Yes. If this isn't wanted behavior, the test cases for it in the caching suite will need to be added to the ignoredTests list in test/cache-interceptor/cache-tests.mjs

@Uzlopak Uzlopak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, I guess it isnt harming

@Uzlopak Uzlopak merged commit c6cc3c1 into nodejs:main Aug 13, 2025
@github-actions github-actions Bot mentioned this pull request Aug 17, 2025
slagiewka pushed a commit to slagiewka/undici that referenced this pull request Feb 14, 2026
* cache-control: no-cache: use quoted-string form

Update comment and test examples of qualified no-cache directives (no-cache=...) to use the quoted-string form instead of the token form.

Per https://httpwg.org/specs/rfc9111.html#cache-response-directive.no-cache:

> This directive uses the quoted-string form of the argument syntax. A sender SHOULD NOT generate the token form (even if quoting appears not to be needed for single-entry lists).

* revert deliberate test case

* revert some changes

---------

Co-authored-by: alxndrsn <alxndrsn>
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.

4 participants