Welcome! Log In Create A New Profile

Advanced

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

Bondarev, Daniil
July 29, 2015 07:30PM
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.

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
Subject Author Views Posted

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

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

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

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

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

Roman Arutyunyan 323 August 07, 2015 04:26PM



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

Online Users

Guests: 267
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