Mercurial > hg > nginx
comparison src/http/ngx_http_request_body.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 | f798ecafec05 |
children |
comparison
equal
deleted
inserted
replaced
9262:106b3832e7ef | 9263:388a801e9bb9 |
---|---|
44 | 44 |
45 if (r != r->main || r->request_body || r->discard_body) { | 45 if (r != r->main || r->request_body || r->discard_body) { |
46 r->request_body_no_buffering = 0; | 46 r->request_body_no_buffering = 0; |
47 | 47 |
48 if (r->request_body && r->request_body->no_buffering) { | 48 if (r->request_body && r->request_body->no_buffering) { |
49 r->headers_in.content_length_n = 0; | 49 r->discard_body = 1; |
50 r->request_body->bufs = NULL; | 50 r->request_body->bufs = NULL; |
51 | 51 |
52 if (r->reading_body) { | 52 if (r->reading_body) { |
53 r->reading_body = 0; | 53 r->reading_body = 0; |
54 r->keepalive = 0; | 54 r->keepalive = 0; |
242 } | 242 } |
243 | 243 |
244 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | 244 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
245 | 245 |
246 r->lingering_close = 1; | 246 r->lingering_close = 1; |
247 r->headers_in.content_length_n = 0; | 247 r->discard_body = 1; |
248 r->request_body->bufs = NULL; | 248 r->request_body->bufs = NULL; |
249 | 249 |
250 r->main->count--; | 250 r->main->count--; |
251 r->read_event_handler = ngx_http_block_reading; | 251 r->read_event_handler = ngx_http_block_reading; |
252 } | 252 } |
317 rc = ngx_http_do_read_client_request_body(r); | 317 rc = ngx_http_do_read_client_request_body(r); |
318 | 318 |
319 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { | 319 if (rc >= NGX_HTTP_SPECIAL_RESPONSE) { |
320 | 320 |
321 r->lingering_close = 1; | 321 r->lingering_close = 1; |
322 r->headers_in.content_length_n = 0; | 322 r->discard_body = 1; |
323 r->request_body->bufs = NULL; | 323 r->request_body->bufs = NULL; |
324 | 324 |
325 r->read_event_handler = ngx_http_block_reading; | 325 r->read_event_handler = ngx_http_block_reading; |
326 ngx_http_finalize_request(r, rc); | 326 ngx_http_finalize_request(r, rc); |
327 } | 327 } |
677 } | 677 } |
678 | 678 |
679 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, | 679 ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, |
680 "http set discard body"); | 680 "http set discard body"); |
681 | 681 |
682 r->discard_body = 1; | |
683 | |
682 #if (NGX_HTTP_V2) | 684 #if (NGX_HTTP_V2) |
683 if (r->stream) { | 685 if (r->stream) { |
684 r->stream->skip_data = 1; | 686 r->stream->skip_data = 1; |
685 | |
686 if (r->headers_in.content_length_n > 0 || r->headers_in.chunked) { | |
687 r->headers_in.content_length_n = 0; | |
688 r->discard_body = 1; | |
689 } | |
690 | |
691 return NGX_OK; | 687 return NGX_OK; |
692 } | 688 } |
693 #endif | 689 #endif |
694 | 690 |
695 #if (NGX_HTTP_V3) | 691 #if (NGX_HTTP_V3) |
696 if (r->http_version == NGX_HTTP_VERSION_30) { | 692 if (r->http_version == NGX_HTTP_VERSION_30) { |
697 | |
698 if (r->headers_in.content_length_n > 0 || r->headers_in.chunked) { | |
699 r->headers_in.content_length_n = 0; | |
700 r->discard_body = 1; | |
701 } | |
702 | |
703 return NGX_OK; | 693 return NGX_OK; |
704 } | 694 } |
705 #endif | 695 #endif |
706 | 696 |
707 if (ngx_http_test_expect(r) != NGX_OK) { | 697 if (ngx_http_test_expect(r) != NGX_OK) { |
715 } | 705 } |
716 | 706 |
717 if (r->headers_in.content_length_n <= 0 && !r->headers_in.chunked) { | 707 if (r->headers_in.content_length_n <= 0 && !r->headers_in.chunked) { |
718 return NGX_OK; | 708 return NGX_OK; |
719 } | 709 } |
720 | |
721 r->discard_body = 1; | |
722 | 710 |
723 size = r->header_in->last - r->header_in->pos; | 711 size = r->header_in->last - r->header_in->pos; |
724 | 712 |
725 if (size || r->headers_in.chunked) { | 713 if (size || r->headers_in.chunked) { |
726 rc = ngx_http_discard_request_body_filter(r, r->header_in); | 714 rc = ngx_http_discard_request_body_filter(r, r->header_in); |