[njs] HTTP: fixed r.headersOut setter for special headers.

Dmitry Volyntsev xeioex at nginx.com
Wed Jul 6 23:56:44 UTC 2022


details:   https://hg.nginx.org/njs/rev/ec90809374c0
branches:  
changeset: 1904:ec90809374c0
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed Jul 06 16:52:50 2022 -0700
description:
HTTP: fixed r.headersOut setter for special headers.

The issue was introduced in 5b7676ec600d (0.7.5) when njs module was
adapted to changes in nginx/1.23 related to header structures.

When special headers (Content-Length, Content-Type, Content-Encoding)
were set, the value of the last outgoing header might be overwritten
with a new set value.

This closes #555 issue on Github.

diffstat:

 nginx/ngx_http_js_module.c |  7 +++++--
 1 files changed, 5 insertions(+), 2 deletions(-)

diffs (27 lines):

diff -r 545d2d21dda5 -r ec90809374c0 nginx/ngx_http_js_module.c
--- a/nginx/ngx_http_js_module.c	Tue Jul 05 22:58:12 2022 -0700
+++ b/nginx/ngx_http_js_module.c	Wed Jul 06 16:52:50 2022 -0700
@@ -3836,7 +3836,6 @@ ngx_http_js_header_out_special(njs_vm_t 
         return NJS_ERROR;
     }
 
-    h = NULL;
     part = &headers->part;
     header = part->elts;
 
@@ -3861,10 +3860,14 @@ ngx_http_js_header_out_special(njs_vm_t 
         if (h->key.len == v->length
             && ngx_strncasecmp(h->key.data, v->start, v->length) == 0)
         {
-            break;
+            goto done;
         }
     }
 
+    h = NULL;
+
+done:
+
     if (h != NULL && s.length == 0) {
         h->hash = 0;
         h = NULL;



More information about the nginx-devel mailing list