Skip to content

Commit

Permalink
reverseproxy: Only change Content-Length when full request is buffered (
Browse files Browse the repository at this point in the history
#5830)

fixes: #5829

Signed-off-by: Fred Cox <mcfedr@gmail.com>
  • Loading branch information
mcfedr committed Jan 9, 2024
1 parent 76611fa commit d9ff7b1
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions modules/caddyhttp/reverseproxy/reverseproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,8 +589,12 @@ func (h Handler) prepareRequest(req *http.Request, repl *caddy.Replacer) (*http.
// feature if absolutely required, if read timeouts are
// set, and if body size is limited
if h.RequestBuffers != 0 && req.Body != nil {
req.Body, req.ContentLength = h.bufferedBody(req.Body, h.RequestBuffers)
req.Header.Set("Content-Length", strconv.FormatInt(req.ContentLength, 10))
var readBytes int64
req.Body, readBytes = h.bufferedBody(req.Body, h.RequestBuffers)
if h.RequestBuffers == -1 {
req.ContentLength = readBytes
req.Header.Set("Content-Length", strconv.FormatInt(req.ContentLength, 10))
}
}

if req.ContentLength == 0 {
Expand Down

0 comments on commit d9ff7b1

Please sign in to comment.