Skip to content

Commit dd0c101

Browse files
WeidiDengmohammed90
authored andcommitted
reverseproxy: Set Content-Length when body is fully buffered (caddyserver#6638)
1 parent b61b85c commit dd0c101

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

modules/caddyhttp/reverseproxy/reverseproxy.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -640,7 +640,8 @@ func (h Handler) prepareRequest(req *http.Request, repl *caddy.Replacer) (*http.
640640
if h.RequestBuffers != 0 && req.Body != nil {
641641
var readBytes int64
642642
req.Body, readBytes = h.bufferedBody(req.Body, h.RequestBuffers)
643-
if h.RequestBuffers == -1 {
643+
// set Content-Length when body is fully buffered
644+
if b, ok := req.Body.(bodyReadCloser); ok && b.body == nil {
644645
req.ContentLength = readBytes
645646
req.Header.Set("Content-Length", strconv.FormatInt(req.ContentLength, 10))
646647
}

0 commit comments

Comments
 (0)