comparison src/http/v2/ngx_http_v2.c @ 9263:388a801e9bb9

Request body: discarded body now treated as no body. Notably, proxying of such requests now uses no Content-Length instead of "Content-Length: 0", and the $content_length variable is empty (instead of "0"). This might be beneficial from correctness point of view, since requests with discarded body, such as during processing of error pages, do not pretend there is a zero-length body, but instead do not contain body at all. For example, this might be important for PUT requests, where a zero-length body could be incorrectly interpreted as a real request body. This also slightly simplifies the code.
author Maxim Dounin <mdounin@mdounin.ru>
date Sat, 27 Apr 2024 18:23:52 +0300
parents ac5635650bc6
children
comparison
equal deleted inserted replaced
9262:106b3832e7ef 9263:388a801e9bb9
1099 stream->in_closed, 0); 1099 stream->in_closed, 0);
1100 1100
1101 if (rc != NGX_OK && rc != NGX_AGAIN) { 1101 if (rc != NGX_OK && rc != NGX_AGAIN) {
1102 1102
1103 stream->skip_data = 1; 1103 stream->skip_data = 1;
1104 r->headers_in.content_length_n = 0; 1104 r->discard_body = 1;
1105 r->request_body->bufs = NULL; 1105 r->request_body->bufs = NULL;
1106 1106
1107 ngx_http_finalize_request(r, rc); 1107 ngx_http_finalize_request(r, rc);
1108 } 1108 }
1109 1109
3763 if (r->headers_in.content_length_n > 0 && r->stream->in_closed) { 3763 if (r->headers_in.content_length_n > 0 && r->stream->in_closed) {
3764 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0, 3764 ngx_log_error(NGX_LOG_INFO, r->connection->log, 0,
3765 "client prematurely closed stream"); 3765 "client prematurely closed stream");
3766 3766
3767 r->stream->skip_data = 1; 3767 r->stream->skip_data = 1;
3768 r->headers_in.content_length_n = 0; 3768 r->discard_body = 1;
3769 3769
3770 ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST); 3770 ngx_http_finalize_request(r, NGX_HTTP_BAD_REQUEST);
3771 goto failed; 3771 goto failed;
3772 } 3772 }
3773 3773
4197 rc = ngx_http_v2_process_request_body(r, NULL, 0, r->stream->in_closed, 1); 4197 rc = ngx_http_v2_process_request_body(r, NULL, 0, r->stream->in_closed, 1);
4198 4198
4199 if (rc != NGX_OK && rc != NGX_AGAIN) { 4199 if (rc != NGX_OK && rc != NGX_AGAIN) {
4200 4200
4201 r->stream->skip_data = 1; 4201 r->stream->skip_data = 1;
4202 r->headers_in.content_length_n = 0; 4202 r->discard_body = 1;
4203 r->request_body->bufs = NULL; 4203 r->request_body->bufs = NULL;
4204 4204
4205 ngx_http_finalize_request(r, rc); 4205 ngx_http_finalize_request(r, rc);
4206 return; 4206 return;
4207 } 4207 }
4262 return; 4262 return;
4263 4263
4264 error: 4264 error:
4265 4265
4266 stream->skip_data = 1; 4266 stream->skip_data = 1;
4267 r->headers_in.content_length_n = 0; 4267 r->discard_body = 1;
4268 r->request_body->bufs = NULL; 4268 r->request_body->bufs = NULL;
4269 4269
4270 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR); 4270 ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
4271 return; 4271 return;
4272 4272