[njs] Fetch: fixed HEAD response handling with large Content-Length.
Dmitry Volyntsev
xeioex at nginx.com
Thu Sep 28 18:01:46 UTC 2023
details: https://hg.nginx.org/njs/rev/a60c0acce58b
branches:
changeset: 2209:a60c0acce58b
user: Dmitry Volyntsev <xeioex at nginx.com>
date: Thu Sep 28 11:00:56 2023 -0700
description:
Fetch: fixed HEAD response handling with large Content-Length.
This closes #658 issue on Github.
diffstat:
nginx/ngx_js_fetch.c | 5 +++--
nginx/t/js_fetch.t | 18 +++++++++++++++++-
2 files changed, 20 insertions(+), 3 deletions(-)
diffs (64 lines):
diff -r ed935fa4805b -r a60c0acce58b nginx/ngx_js_fetch.c
--- a/nginx/ngx_js_fetch.c Fri Sep 22 13:00:06 2023 -0700
+++ b/nginx/ngx_js_fetch.c Thu Sep 28 11:00:56 2023 -0700
@@ -2426,8 +2426,9 @@ ngx_js_http_process_headers(ngx_js_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 -r ed935fa4805b -r a60c0acce58b nginx/t/js_fetch.t
--- a/nginx/t/js_fetch.t Fri Sep 22 13:00:06 2023 -0700
+++ b/nginx/t/js_fetch.t Thu Sep 28 11:00:56 2023 -0700
@@ -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 @@ my $p2 = port(8082);
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'
'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 .
More information about the nginx-devel
mailing list