Skip to content

The "Vary: accept-encoding" header is not always set #3292

@kanongil

Description

@kanongil

When hapi only sometimes sets the vary header, based on input headers, it can cause caching issues.

I noticed that this is done for the accept-encoding header here:

hapi/lib/transmit.js

Lines 207 to 209 in 26aaff3

if (request.headers['accept-encoding']) {
response.vary('accept-encoding');
}
.

If a caching agent receives this response to a request without the accept-encoding header, it won't know to re-fetch the resource when another requests is made with the header, thus returning an incorrect response to the client.

The simple fix is to remove the if. Ideally it should only include the vary header for routes that serves different responses depending on the accept-encoding header. Maybe some kind of switch is needed?

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions