[njs] Fetch: accepting response headers with underscore characters.

noreply at nginx.com noreply at nginx.com
Tue Feb 25 00:50:02 UTC 2025


details:   https://github.com/nginx/njs/commit/18977e022b2a9f9f03c2dc5ae4bbc930a2f30855
branches:  master
commit:    18977e022b2a9f9f03c2dc5ae4bbc930a2f30855
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Fri, 21 Feb 2025 23:03:46 -0800
description:
Fetch: accepting response headers with underscore characters.

This fixes #856 on Github.

---
 nginx/ngx_js_fetch.c |  2 +-
 nginx/t/js_fetch.t   | 12 +++++++++++-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/nginx/ngx_js_fetch.c b/nginx/ngx_js_fetch.c
index 1c5a961d..cd6e54f6 100644
--- a/nginx/ngx_js_fetch.c
+++ b/nginx/ngx_js_fetch.c
@@ -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;
             }
 
diff --git a/nginx/t/js_fetch.t b/nginx/t/js_fetch.t
index 0e107c89..ae9d1f61 100644
--- a/nginx/t/js_fetch.t
+++ b/nginx/t/js_fetch.t
@@ -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 .


More information about the nginx-devel mailing list