Skip to content

fix: send the immutable Cache-Control directive as its own field-line - #315

Open
bilashcse wants to merge 3 commits into
pillarjs:masterfrom
bilashcse:fix/immutable-separate-cache-control
Open

fix: send the immutable Cache-Control directive as its own field-line#315
bilashcse wants to merge 3 commits into
pillarjs:masterfrom
bilashcse:fix/immutable-separate-cache-control

Conversation

@bilashcse

Copy link
Copy Markdown

Problem

send appends the immutable directive to the max-age value, so a single field-line goes on the wire:

Cache-Control: public, max-age=31536000, immutable

public, max-age=<seconds> on its own is a value an HTTP/3 QPACK encoder can match against the static table, but the combined value is not, so turning on immutable makes the header more expensive to encode. This was reported in expressjs/serve-static#149, where the suggestion (and the MDN note quoted there) is to split the value across two field-lines instead.

Fix

When immutable is enabled, Cache-Control is now set as two field-lines:

Cache-Control: public, max-age=31536000
Cache-Control: immutable

HTTP caches combine repeated Cache-Control field-lines, so the effective set of directives is unchanged and clients keep seeing the same behaviour. Nothing changes when immutable is disabled.

Tests

Two cases were added under describe('immutable') that inspect rawHeaders to assert the exact field-lines that go on the wire, one with immutable: true and one with immutable: false, together with a shouldHaveHeaderValues helper. The existing should set immutable directive in Cache-Control test is left untouched and still passes, because Node joins repeated field-lines when populating res.headers.

The suite was run on a fork before opening this PR: lint plus Node.js 18-25 on both ubuntu-latest and windows-latest all pass. The only failing job there is coverage, which cannot reach Coveralls from a fork.

Docs

README.md now documents the two field-lines under the immutable option and explains why the value is split.

Refs expressjs/serve-static#149

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