Remove etag from response when modifying headers

This commit is contained in:
Sander Declerck 2025-11-13 16:27:42 +01:00
parent 752504dcc8
commit dc6f37b3ec
No known key found for this signature in database
3 changed files with 18 additions and 8 deletions

View file

@ -34,9 +34,10 @@ export function isPackageInfoUrl(url) {
/**
*
* @param {Buffer} body
* @param {NodeJS.Dict<string | string[]> | undefined} headers
* @returns Buffer
*/
export function modifyNpmInfoResponse(body) {
export function modifyNpmInfoResponse(body, headers) {
try {
if (body.byteLength === 0) {
return body;
@ -70,6 +71,11 @@ export function modifyNpmInfoResponse(body) {
if (timestamp > cutOff) {
deleteVersionFromJson(bodyJson, version);
if (headers) {
// When modifying the response, the etag no longer matches the content
// so the etag needs to be removed before sending the response.
delete headers["etag"];
}
continue;
}
}