@marcel91200 / caddy Mirror · read-only / commits / 613d544a
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 12, 13:15 UTC

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.

Matthew Holt committed Apr 22, 2024 at 13:11 UTC 613d544a4775b831595f223028fee76b980aa003
1 file changed +8 -1
modules/caddyhttp/reverseproxy/reverseproxy.go
+8 -1
@@ -444,6 +444,13 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyht
444 if done {
445 break
446 }
447 + if h.VerboseLogs {
448 + var lbWait time.Duration
449 + if h.LoadBalancing != nil {
450 + lbWait = time.Duration(h.LoadBalancing.TryInterval)
451 + }
452 + h.logger.Debug("retrying", zap.Error(proxyErr), zap.Duration("after", lbWait))
453 + }
454 retries++
455 }
456
@@ -1131,7 +1138,7 @@ func (h Handler) bufferedBody(originalBody io.ReadCloser, limit int64) (io.ReadC
1138 buf.Reset()
1139 if limit > 0 {
1140 n, err := io.CopyN(buf, originalBody, limit)
1134 - if err != nil || n == limit {
1141 + if (err != nil && err != io.EOF) || n == limit {
1142 return bodyReadCloser{
1143 Reader: io.MultiReader(buf, originalBody),
1144 buf: buf,