From 148c75678cd4171338c31d4ed4c02411736d5fe9 Mon Sep 17 00:00:00 2001 From: Maxim Dounin Date: Sat, 27 Apr 2024 18:18:13 +0300 Subject: [PATCH] Proxy: use zero Content-Length while discarding request body. Previously, r->headers_in.content_length_n was used, which is not 0 till the request body is fully discarded, and the request might hang. Adapted for nginx: the same change is applied to the HTTP/2 proxy module (proxy_http_version 2), which is not present in freenginx and used r->headers_in.content_length_n in the same way. With an HTTP/2 upstream, the stale length resulted in the request being rejected by the upstream, since the stream was closed without the body. Co-authored-by: Elijah Zupancic Signed-off-by: Elijah Zupancic Origin: --- src/http/modules/ngx_http_proxy_module.c | 3 +++ src/http/modules/ngx_http_proxy_v2_module.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c index 99b915c52..10b5b7535 100644 --- a/src/http/modules/ngx_http_proxy_module.c +++ b/src/http/modules/ngx_http_proxy_module.c @@ -1307,6 +1307,9 @@ ngx_http_proxy_create_request(ngx_http_request_t *r) ctx->internal_body_length = -1; ctx->internal_chunked = 1; + } else if (r->discard_body) { + ctx->internal_body_length = 0; + } else { ctx->internal_body_length = r->headers_in.content_length_n; } diff --git a/src/http/modules/ngx_http_proxy_v2_module.c b/src/http/modules/ngx_http_proxy_v2_module.c index a0ccb5d26..727fa9d4b 100644 --- a/src/http/modules/ngx_http_proxy_v2_module.c +++ b/src/http/modules/ngx_http_proxy_v2_module.c @@ -496,6 +496,9 @@ ngx_http_proxy_v2_create_request(ngx_http_request_t *r) } else if (r->headers_in.chunked && r->reading_body) { ctx->ctx.internal_body_length = -1; + } else if (r->discard_body) { + ctx->ctx.internal_body_length = 0; + } else { ctx->ctx.internal_body_length = r->headers_in.content_length_n; }