From e99c1cc88b4fdb8a569f8d52ca8fc77dcc9d9999 Mon Sep 17 00:00:00 2001 From: Dmitry Volyntsev Date: Thu, 28 Sep 2023 11:00:56 -0700 Subject: [PATCH] Fetch: fixed HEAD response handling with large Content-Length. This closes #658 issue on Github. --- nginx/ngx_js_fetch.c | 5 +++-- nginx/t/js_fetch.t | 18 +++++++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/nginx/ngx_js_fetch.c b/nginx/ngx_js_fetch.c index 0802a00b..96e1845f 100644 --- a/nginx/ngx_js_fetch.c +++ b/nginx/ngx_js_fetch.c @@ -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"); diff --git a/nginx/t/js_fetch.t b/nginx/t/js_fetch.t index 428be90f..e0763a6a 100644 --- a/nginx/t/js_fetch.t +++ b/nginx/t/js_fetch.t @@ -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', <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.*$/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 . -- 2.47.3