diff options
author | Matthew Holt <[email protected]> | 2024-04-22 13:11:59 -0600 |
---|---|---|
committer | Matthew Holt <[email protected]> | 2024-04-22 13:12:10 -0600 |
commit | 613d544a4775b831595f223028fee76b980aa003 (patch) | |
tree | 740328046a27b8f504f4b70c78975c0945acdbe8 | |
parent | 726a9a8fde60e4d72282b24fb553573fb388607c (diff) | |
download | caddy-613d544a4775b831595f223028fee76b980aa003.tar.gz caddy-613d544a4775b831595f223028fee76b980aa003.zip |
reverseproxy: Accept EOF when buffering
Before this change, a read of size (let's say) < 10, into a buffer of size 10, will return EOF because we're using CopyN to limit to the size of the buffer. That resulted in the body being read from later, which should only happen if it couldn't fit in the buffer.
With this change, the body is properly NOT set when it can all fit in the buffer.
-rw-r--r-- | modules/caddyhttp/reverseproxy/reverseproxy.go | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/modules/caddyhttp/reverseproxy/reverseproxy.go b/modules/caddyhttp/reverseproxy/reverseproxy.go index deba304a7..048539e93 100644 --- a/modules/caddyhttp/reverseproxy/reverseproxy.go +++ b/modules/caddyhttp/reverseproxy/reverseproxy.go @@ -444,6 +444,13 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyht if done { break } + if h.VerboseLogs { + var lbWait time.Duration + if h.LoadBalancing != nil { + lbWait = time.Duration(h.LoadBalancing.TryInterval) + } + h.logger.Debug("retrying", zap.Error(proxyErr), zap.Duration("after", lbWait)) + } retries++ } @@ -1131,7 +1138,7 @@ func (h Handler) bufferedBody(originalBody io.ReadCloser, limit int64) (io.ReadC buf.Reset() if limit > 0 { n, err := io.CopyN(buf, originalBody, limit) - if err != nil || n == limit { + if (err != nil && err != io.EOF) || n == limit { return bodyReadCloser{ Reader: io.MultiReader(buf, originalBody), buf: buf, |