aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorWeidiDeng <[email protected]>2024-10-17 09:09:26 +0800
committerWeidiDeng <[email protected]>2024-10-17 09:09:26 +0800
commit8c11e51747ab834f5a5b581fcdb403ee9449cf23 (patch)
tree3d3e0d6ab8ff30d49d86ecd9b49158d5be0bd7b6
parentc6f2979986d87d7236b132c687c8887c92248dd8 (diff)
downloadcaddy-8c11e51747ab834f5a5b581fcdb403ee9449cf23.tar.gz
caddy-8c11e51747ab834f5a5b581fcdb403ee9449cf23.zip
set content-length when body is fully bufferedbuffer-content-length
-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 123bf774b..c81368813 100644
--- a/modules/caddyhttp/reverseproxy/reverseproxy.go
+++ b/modules/caddyhttp/reverseproxy/reverseproxy.go
@@ -625,7 +625,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))
}