Welcome! Log In Create A New Profile

Advanced

Re: [PATCH] Set Content-Length to 0 when proxying requests with discarded body

Roman Arutyunyan
August 07, 2015 04:26PM
Hello Daniil,

> On 29 Jul 2015, at 16:28, Bondarev, Daniil <bondarev@amazon.com> wrote:
>
> Hello,
>
> We have a use case where we need to discard request body before proxying
> request to the upstream. To do this we call ngx_http_discard_request_body,
> but it uses r->headers_in.content_length_n to store the amount of data nginx
> wants to receive next time, so it won't be 0 until nginx read all bytes from the
> client. So if proxy_request_buffering is set to off, nginx ends up sending
> non-0 Content-Length header to the upstream without a body.

If you have no "proxy_pass_request_body off” or “proxy_set_body ‘’", it’s assumed
that you want your request body to be passed to the upstream. Missing body
is an error and probably it’s not a good idea to silently ignore it setting
zero Content-Length.

> The following patch fixes this behavior.
>
> # HG changeset patch
> # User Daniil Bondarev <bondarev@amazon.com>
> # Date 1438119116 25200
> # Node ID ddefee93b698b9261a147a08f42a07810efa2dab
> # Parent 341e4303d25be159d4773b819d0ec055ba711afb
> Set Content-Length to 0 when proxying requests with discarded body
>
> diff -r 341e4303d25b -r ddefee93b698 src/http/modules/ngx_http_proxy_module.c
> --- a/src/http/modules/ngx_http_proxy_module.c Thu Jul 16 14:20:48 2015 +0300
> +++ b/src/http/modules/ngx_http_proxy_module.c Tue Jul 28 14:31:56 2015 -0700
> @@ -1221,6 +1221,9 @@
> ctx->internal_body_length = body_len;
> len += body_len;
>
> + } else if (r->discard_body) {
> + ctx->internal_body_length = 0;
> +
> } else if (r->headers_in.chunked && r->reading_body) {
> ctx->internal_body_length = -1;
> ctx->internal_chunked = 1;
>
> _______________________________________________
> nginx-devel mailing list
> nginx-devel@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx-devel
>

--
Roman Arutyunyan



_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH] Set Content-Length to 0 when proxying requests with discarded body

Bondarev, Daniil 767 July 29, 2015 07:30PM

Re: [PATCH] Set Content-Length to 0 when proxying requests with discarded body

Bondarev, Daniil 299 August 07, 2015 02:14PM

Re: [PATCH] Set Content-Length to 0 when proxying requests with discarded body

Roman Arutyunyan 326 August 07, 2015 04:26PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 155
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready