aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorWeidiDeng <[email protected]>2024-12-18 07:36:13 +0800
committerGitHub <[email protected]>2024-12-17 23:36:13 +0000
commitc864b82ae13f9dc920ebd8782fe7c5b7007a3e1b (patch)
tree8e9f3254c7f92cd9bcfb9a078fc16bbd5175b42c
parente76405d55058b0a3e5ba222b44b5ef00516116aa (diff)
downloadcaddy-c864b82ae13f9dc920ebd8782fe7c5b7007a3e1b.tar.gz
caddy-c864b82ae13f9dc920ebd8782fe7c5b7007a3e1b.zip
reverseproxy: Set Content-Length when body is fully buffered (#6638)
-rw-r--r--modules/caddyhttp/reverseproxy/reverseproxy.go3
1 files changed, 2 insertions, 1 deletions
diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go
index 64804e18b..f9485c570 100644
--- a/modules/caddyhttp/reverseproxy/reverseproxy.go
+++ b/modules/caddyhttp/reverseproxy/reverseproxy.go
@@ -639,7 +639,8 @@ func (h Handler) prepareRequest(req *http.Request, repl *caddy.Replacer) (*http.
if h.RequestBuffers != 0 && req.Body != nil {
var readBytes int64
req.Body, readBytes = h.bufferedBody(req.Body, h.RequestBuffers)
- if h.RequestBuffers == -1 {
+ // set Content-Length when body is fully buffered
+ if b, ok := req.Body.(bodyReadCloser); ok && b.body == nil {
req.ContentLength = readBytes
req.Header.Set("Content-Length", strconv.FormatInt(req.ContentLength, 10))
}