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:
|
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); |
|
} |
I have a case where I need to do my own compression of the content, setting where I set the
content-encodingheader to disable the built-in processing. As it is, this also sets thevaryheader with anaccept-encodingvalue during the transmit step.Since I always set the
content-encodingheader, I do not want the response tovaryas 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-encodingheader, is a bit of an overreach. Then it can be solved as a (possibly breaking) bug fix, by moving theresponse.vary('accept-encoding');line after thecontent-encodingheader check.The relevant logic:
hapi/lib/compression.js
Lines 78 to 99 in 93378b2