Mercurial > hg > nginx
changeset 9260:ac5635650bc6
Request body: handling of body after unbuffered reading.
As long as unbuffered reading of the request body was used, and an attempt
to read the request body is made again, such as when redirecting the request
to an error page, the request body is now cleared to make sure it can be
used safely.
Further, the r->reading_body flag, if it is still set, is cleared (along with
disabling keepalive and enabling lingering close), so the code which uses
the request body, such as when proxying, is not confused and doesn't try
to use "Transfer-Encoding: chunked".
Note that this change makes the workaround for HTTP/2 issues with unbuffered
proxying and error pages, as introduced in 7561:9f1f9d6e056a, ineffective
(since r->reading_body now cleared along with r->reading_body_no_buffering).
Though the workaround is anyway not needed after 7924:d9e009b39596, hence
it is removed.
This makes it safer to use complex processing of error pages with unbuffered
proxying.
author | Maxim Dounin <mdounin@mdounin.ru> |
---|---|
date | Sat, 27 Apr 2024 18:22:07 +0300 |
parents | 81082b5521dd |
children | f798ecafec05 |
files | src/http/ngx_http_request.h src/http/ngx_http_request_body.c src/http/v2/ngx_http_v2.c |
diffstat | 3 files changed, 15 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/src/http/ngx_http_request.h Sat Apr 27 18:21:38 2024 +0300 +++ b/src/http/ngx_http_request.h Sat Apr 27 18:22:07 2024 +0300 @@ -305,6 +305,7 @@ ngx_chain_t *busy; ngx_http_chunked_t *chunked; ngx_http_client_body_handler_pt post_handler; + unsigned no_buffering:1; unsigned filter_need_buffering:1; unsigned last_sent:1; unsigned last_saved:1;
--- a/src/http/ngx_http_request_body.c Sat Apr 27 18:21:38 2024 +0300 +++ b/src/http/ngx_http_request_body.c Sat Apr 27 18:22:07 2024 +0300 @@ -44,6 +44,18 @@ if (r != r->main || r->request_body || r->discard_body) { r->request_body_no_buffering = 0; + + if (r->request_body && r->request_body->no_buffering) { + r->headers_in.content_length_n = 0; + r->request_body->bufs = NULL; + + if (r->reading_body) { + r->reading_body = 0; + r->keepalive = 0; + r->lingering_close = 1; + } + } + post_handler(r); return NGX_OK; } @@ -72,6 +84,7 @@ * rb->busy = NULL; * rb->chunked = NULL; * rb->received = 0; + * rb->no_buffering = 0; * rb->filter_need_buffering = 0; * rb->last_sent = 0; * rb->last_saved = 0; @@ -220,6 +233,7 @@ } else { /* rc == NGX_AGAIN */ r->reading_body = 1; + r->request_body->no_buffering = 1; } r->read_event_handler = ngx_http_block_reading;
--- a/src/http/v2/ngx_http_v2.c Sat Apr 27 18:21:38 2024 +0300 +++ b/src/http/v2/ngx_http_v2.c Sat Apr 27 18:22:07 2024 +0300 @@ -1078,13 +1078,6 @@ r = stream->request; fc = r->connection; - if (r->reading_body && !r->request_body_no_buffering) { - ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, - "skipping http2 DATA frame"); - - return ngx_http_v2_state_skip_padded(h2c, pos, end); - } - if (r->headers_in.content_length_n < 0 && !r->headers_in.chunked) { ngx_log_debug0(NGX_LOG_DEBUG_HTTP, h2c->connection->log, 0, "skipping http2 DATA frame");