Skip to content

Commit d9ff7b1

Browse files
authored
reverseproxy: Only change Content-Length when full request is buffered (#5830)
fixes: #5829 Signed-off-by: Fred Cox <[email protected]>
1 parent 76611fa commit d9ff7b1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

modules/caddyhttp/reverseproxy/reverseproxy.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -589,8 +589,12 @@ func (h Handler) prepareRequest(req *http.Request, repl *caddy.Replacer) (*http.
589589
// feature if absolutely required, if read timeouts are
590590
// set, and if body size is limited
591591
if h.RequestBuffers != 0 && req.Body != nil {
592-
req.Body, req.ContentLength = h.bufferedBody(req.Body, h.RequestBuffers)
593-
req.Header.Set("Content-Length", strconv.FormatInt(req.ContentLength, 10))
592+
var readBytes int64
593+
req.Body, readBytes = h.bufferedBody(req.Body, h.RequestBuffers)
594+
if h.RequestBuffers == -1 {
595+
req.ContentLength = readBytes
596+
req.Header.Set("Content-Length", strconv.FormatInt(req.ContentLength, 10))
597+
}
594598
}
595599

596600
if req.ContentLength == 0 {

0 commit comments

Comments
 (0)