]> git.kaiwu.me - njs.git/commitdiff
Fetch: fixed HEAD response handling with large Content-Length.
authorDmitry Volyntsev <xeioex@nginx.com>
Thu, 28 Sep 2023 18:00:56 +0000 (11:00 -0700)
committerDmitry Volyntsev <xeioex@nginx.com>
Thu, 28 Sep 2023 18:00:56 +0000 (11:00 -0700)
This closes #658 issue on Github.

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

index 0802a00b639bbd8b981d28755bffaef5e1c25c27..96e1845f920f9f9c0bf47fea775bd13649fd4054 100644 (file)
@@ -2426,8 +2426,9 @@ ngx_js_http_process_headers(ngx_js_http_t *http)
                     return NGX_ERROR;
                 }
 
-                if (hp->content_length_n
-                    > (off_t) http->max_response_body_size)
+                if (!http->header_only
+                    && hp->content_length_n
+                       > (off_t) http->max_response_body_size)
                 {
                     ngx_js_http_error(http, 0,
                                       "fetch content length is too large");
index 428be90fdf97987d4bd8e49422fa683ce54911d0..e0763a6aa8c163c6329b7f270bb2c6336f4b1bc2 100644 (file)
@@ -46,6 +46,8 @@ http {
         listen       127.0.0.1:8080;
         server_name  localhost;
 
+        js_fetch_max_response_buffer_size 128k;
+
         location /njs {
             js_content test.njs;
         }
@@ -399,7 +401,7 @@ $t->write_file('test.js', <<EOF);
                      host_header, multi, loc, property};
 EOF
 
-$t->try_run('no njs.fetch')->plan(35);
+$t->try_run('no njs.fetch')->plan(36);
 
 $t->run_daemon(\&http_daemon, port(8082));
 $t->waitforsocket('127.0.0.1:' . port(8082));
@@ -493,6 +495,13 @@ like(http_get('/host_header?host=FOOBAR'), qr/200 OK.*FOOBAR$/s,
        'fetch host header');
 }
 
+TODO: {
+local $TODO = 'not yet' unless has_version('0.8.2');
+
+like(http_get('/body_special?loc=head/large&method=HEAD'),
+       qr/200 OK.*<empty>$/s, 'fetch head method large content-length');
+}
+
 ###############################################################################
 
 sub has_version {
@@ -620,6 +629,13 @@ sub http_daemon {
                                "Connection: close" . CRLF .
                                CRLF;
 
+               } elsif ($uri eq '/head/large') {
+                       print $client
+                               "HTTP/1.1 200 OK" . CRLF .
+                               "Content-Length: 1000000" . CRLF .
+                               "Connection: close" . CRLF .
+                               CRLF;
+
                } elsif ($uri eq '/parted') {
                        print $client
                                "HTTP/1.1 200 OK" . CRLF .