# HG changeset patch # User Maxim Dounin # Date 1427326290 -10800 # Node ID 24ccec3c4a87d90c06178431898579120f6bffcb # Parent 166c2c19c5229f8e96385bbd4d7a6eeb0f0fbe68 Proxy: fixed proxy_request_buffering and chunked with preread body. If any preread body bytes were sent in the first chain, chunk size was incorrectly added before the whole chain, including header, resulting in an invalid request sent to upstream. Fixed to properly add chunk size after the header. diff --git a/src/http/modules/ngx_http_proxy_module.c b/src/http/modules/ngx_http_proxy_module.c --- a/src/http/modules/ngx_http_proxy_module.c +++ b/src/http/modules/ngx_http_proxy_module.c @@ -1503,7 +1503,7 @@ ngx_http_proxy_body_output_filter(void * u_char *chunk; ngx_int_t rc; ngx_buf_t *b; - ngx_chain_t *out, *cl, *tl, **ll; + ngx_chain_t *out, *cl, *tl, **ll, **fl; ngx_http_proxy_ctx_t *ctx; ngx_log_debug0(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, @@ -1546,6 +1546,7 @@ ngx_http_proxy_body_output_filter(void * size = 0; cl = in; + fl = ll; for ( ;; ) { ngx_log_debug1(NGX_LOG_DEBUG_HTTP, r->connection->log, 0, @@ -1602,8 +1603,8 @@ ngx_http_proxy_body_output_filter(void * b->pos = chunk; b->last = ngx_sprintf(chunk, "%xO" CRLF, size); - tl->next = out; - out = tl; + tl->next = *fl; + *fl = tl; } if (cl->buf->last_buf) {