Skip to content

Custom "content-encoding" without vary header #3964

@kanongil

Description

@kanongil

I have a case where I need to do my own compression of the content, setting where I set the content-encoding header to disable the built-in processing. As it is, this also sets the vary header with an accept-encoding value during the transmit step.

Since I always set the content-encoding header, I do not want the response to vary as such. However, there is no response level option to disable this.

Note, it might not even need to be an option, as unconditionally setting the header for any response with a content-encoding header, is a bit of an overreach. Then it can be solved as a (possibly breaking) bug fix, by moving the response.vary('accept-encoding'); line after the content-encoding header check.

The relevant logic:

hapi/lib/compression.js

Lines 78 to 99 in 93378b2

encoding(response, length) {
const request = response.request;
if (!request._core.settings.compression ||
(length !== null && length < request._core.settings.compression.minBytes)) {
return null;
}
const mime = request._core.mime.type(response.headers['content-type'] || 'application/octet-stream');
if (!mime.compressible) {
return null;
}
response.vary('accept-encoding');
if (response.headers['content-encoding']) {
return null;
}
return (request.info.acceptEncoding === 'identity' ? null : request.info.acceptEncoding);
}

Metadata

Metadata

Assignees

Labels

featureNew functionality or improvement

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions