Skip to content

Commit

Permalink
reverseproxy: only change the content-length header when the full req…
Browse files Browse the repository at this point in the history
…uest was buffered

fixes: caddyserver#5829

Signed-off-by: Fred Cox <[email protected]>
  • Loading branch information
mcfedr committed Oct 11, 2023
1 parent 2a6859a commit 57c9dd4
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 @@ -582,8 +582,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 57c9dd4

Please sign in to comment.