Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom "content-encoding" without vary header #3964

kanongil opened this issue Aug 8, 2019 · 2 comments


Copy link

commented Aug 8, 2019

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:


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;
if (response.headers['content-encoding']) {
return null;
return ( === 'identity' ? null :;


This comment has been minimized.

Copy link
Member Author

commented Aug 9, 2019

Another option, that might work better, is for hapi to expose forced content encoding through a response object method. That way I don't need to bother with the encoding myself.

Note that I can't use a route-level option since I need to do this in response to a specific query parameter.

Edit: Such an option could also be used to signal that identity encoding should be used, thus disabling compression for the response.

@hueniverse hueniverse self-assigned this Sep 14, 2019
@hueniverse hueniverse added the feature label Sep 14, 2019
@hueniverse hueniverse added this to the 18.3.3 milestone Sep 14, 2019

This comment has been minimized.

Copy link

commented Sep 14, 2019

How do you find yourself in all these HTTP rabbit holes...? ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants
You can’t perform that action at this time.