diff src/http/ngx_http_request_body.c @ 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
line wrap: on
line diff
--- a/src/http/ngx_http_request_body.c
+++ b/src/http/ngx_http_request_body.c
@@ -44,6 +44,18 @@ ngx_http_read_client_request_body(ngx_ht
 
     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 @@ ngx_http_read_client_request_body(ngx_ht
      *     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 @@ done:
         } else {
             /* rc == NGX_AGAIN */
             r->reading_body = 1;
+            r->request_body->no_buffering = 1;
         }
 
         r->read_event_handler = ngx_http_block_reading;