From 9ae106730e28f89aed7987d40c9387057df4784e Mon Sep 17 00:00:00 2001 From: skokalin Date: Wed, 28 May 2025 17:47:42 +0400 Subject: node.js: Fixed issue with duplicate headers in response It fixes losing context in response in cases when there are 2 or more headers with the same name. The prev implementation used to use foreach function which uses local lexical environment and did not find this.headers_len locally, which causes crash of the http server module. It was replaced with a for loop in order to make access for this.headers_len variable and improve performance of calculation. Closes: https://github.com/nginx/unit/issues/1621 Signed-off-by: Andrew Clayton --- src/nodejs/unit-http/http_server.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/nodejs/unit-http/http_server.js b/src/nodejs/unit-http/http_server.js index 4e1c190e..68400b84 100644 --- a/src/nodejs/unit-http/http_server.js +++ b/src/nodejs/unit-http/http_server.js @@ -153,9 +153,9 @@ ServerResponse.prototype._removeHeader = function _removeHeader(lc_name) { this.headers_count -= value.length; this.headers_len -= value.length * name_len; - value.forEach(function(val) { - this.headers_len -= Buffer.byteLength(val + "", 'latin1'); - }); + for (let i = 0; i < value.length; i++){ + this.headers_len -= Buffer.byteLength(value[i] + "", 'latin1'); + } return; } -- cgit