[njs] Fetch: fixed Headers.set().

Dmitry Volyntsev xeioex at nginx.com
Thu Nov 16 00:24:53 UTC 2023


details:   https://hg.nginx.org/njs/rev/0213cb43bfce
branches:  
changeset: 2233:0213cb43bfce
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed Nov 15 15:07:20 2023 -0800
description:
Fetch: fixed Headers.set().

This closes #680 issue on Github.

diffstat:

 nginx/ngx_js_fetch.c       |  10 ++++++++++
 nginx/t/js_fetch_objects.t |   5 +++++
 2 files changed, 15 insertions(+), 0 deletions(-)

diffs (38 lines):

diff -r f936754f6f62 -r 0213cb43bfce nginx/ngx_js_fetch.c
--- a/nginx/ngx_js_fetch.c	Thu Nov 09 17:09:16 2023 -0800
+++ b/nginx/ngx_js_fetch.c	Wed Nov 15 15:07:20 2023 -0800
@@ -3637,9 +3637,19 @@ ngx_headers_js_ext_set(njs_vm_t *vm, njs
                 ph = &(*ph)->next;
                 *pp = NULL;
             }
+
+            goto done;
         }
     }
 
+    ret = ngx_js_headers_append(vm, headers, name.start, name.length,
+                                value.start, value.length);
+    if (ret != NJS_OK) {
+        return NJS_ERROR;
+    }
+
+done:
+
     njs_value_undefined_set(retval);
 
     return NJS_OK;
diff -r f936754f6f62 -r 0213cb43bfce nginx/t/js_fetch_objects.t
--- a/nginx/t/js_fetch_objects.t	Thu Nov 09 17:09:16 2023 -0800
+++ b/nginx/t/js_fetch_objects.t	Wed Nov 15 15:07:20 2023 -0800
@@ -206,6 +206,11 @@ my $p0 = port(8080);
                 h.set('a', '#');
                 return h.get('a');
              }, '#'],
+             ['set on empty', () => {
+                var h = new Headers([]);
+                h.set('x-test', '1234');
+                return h.get('x-test');
+             }, '1234'],
         ];
 
         run(r, tests);


More information about the nginx-devel mailing list