[PATCH] SCGI: fixed handling of unbuffered request body
Maxim Dounin
mdounin at mdounin.ru
Sat May 9 21:01:13 UTC 2026
# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1778251703 -10800
# Fri May 08 17:48:23 2026 +0300
# Node ID 8cee4d35c15b7c6d3b788b1608cd13bc2ad52cdb
# Parent 874f5f884e0a09f6433f0385ba195a71e94cb5d2
SCGI: fixed handling of unbuffered request body.
Previously, size of the request body as sent in the CONTENT_LENGTH param
was calculated based on the size of the request buffers available. This is,
however, wrong for unbuffered request body, since the request body might
not be fully available yet.
The fix is to use r->headers_in.content_length_n (as long as it is available
and there is a body), much like other modules do.
See also:
https://github.com/nginx/nginx/commit/ec714d52bd4914d52a113234c16e1855d9ac7dcf
diff --git a/src/http/modules/ngx_http_scgi_module.c b/src/http/modules/ngx_http_scgi_module.c
--- a/src/http/modules/ngx_http_scgi_module.c
+++ b/src/http/modules/ngx_http_scgi_module.c
@@ -649,11 +649,9 @@ ngx_http_scgi_create_request(ngx_http_re
u_char buffer[NGX_OFF_T_LEN];
content_length_n = 0;
- body = r->upstream->request_bufs;
-
- while (body) {
- content_length_n += ngx_buf_size(body->buf);
- body = body->next;
+
+ if (r->headers_in.content_length_n > 0 && !r->discard_body) {
+ content_length_n = r->headers_in.content_length_n;
}
content_length.data = buffer;
More information about the nginx-devel
mailing list