]> git.kaiwu.me - njs.git/commitdiff
Fetch: accepting response headers with underscore characters.
authorDmitry Volyntsev <xeioex@nginx.com>
Sat, 22 Feb 2025 07:03:46 +0000 (23:03 -0800)
committerDmitry Volyntsev <xeioexception@gmail.com>
Tue, 25 Feb 2025 00:49:43 +0000 (16:49 -0800)
This fixes #856 on Github.

nginx/ngx_js_fetch.c
nginx/t/js_fetch.t

index 1c5a961dd1dd9d3a0dffbe568e099412025df815..cd6e54f6b0810193900a8ac50acae9ba7d21c707 100644 (file)
@@ -2868,7 +2868,7 @@ ngx_js_http_parse_header_line(ngx_js_http_parse_t *hp, ngx_buf_t *b)
                 break;
             }
 
-            if (ch == '-') {
+            if (ch == '-' || ch == '_') {
                 break;
             }
 
index 0e107c8936f2cd0df4ed9117250df3cd9bc46518..ae9d1f614a0bccb144a3968c525f48b47bfe6b6f 100644 (file)
@@ -413,7 +413,7 @@ $t->try_run('no njs.fetch');
 
 plan(skip_all => 'not yet') if http_get('/engine') =~ /QuickJS$/m;
 
-$t->plan(36);
+$t->plan(37);
 
 $t->run_daemon(\&http_daemon, port(8082));
 $t->waitforsocket('127.0.0.1:' . port(8082));
@@ -479,6 +479,8 @@ like(http_get('/chain'), qr/200 OK.*SUCCESS$/s, 'fetch chain');
 like(http_get('/header_iter?loc=duplicate_header_large'),
        qr/\["A:a","B:a","C:a","D:a","E:a","F:a","G:a","H:a","Moo:a, ?b"]$/s,
        'fetch header duplicate large');
+like(http_get('/header_iter?loc=underscore_header'),
+       qr/\["F_O_O:b","Foo:a"]$/s, 'fetch header underscore');
 
 TODO: {
 local $TODO = 'not yet' unless has_version('0.7.7');
@@ -621,6 +623,14 @@ sub http_daemon {
                                "Connection: close" . CRLF .
                                CRLF;
 
+               } elsif ($uri eq '/underscore_header') {
+                       print $client
+                               "HTTP/1.1 200 OK" . CRLF .
+                               "Foo: a" . CRLF .
+                               "F_O_O: b" . CRLF .
+                               "Connection: close" . CRLF .
+                               CRLF;
+
                } elsif ($uri eq '/headers') {
                        print $client
                                "HTTP/1.1 200 OK" . CRLF .