mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-26 21:53:48 +03:00
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.
This commit is contained in:
parent
726a9a8fde
commit
613d544a47
1 changed files with 8 additions and 1 deletions
|
@ -444,6 +444,13 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyht
|
||||||
if done {
|
if done {
|
||||||
break
|
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++
|
retries++
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1131,7 +1138,7 @@ func (h Handler) bufferedBody(originalBody io.ReadCloser, limit int64) (io.ReadC
|
||||||
buf.Reset()
|
buf.Reset()
|
||||||
if limit > 0 {
|
if limit > 0 {
|
||||||
n, err := io.CopyN(buf, originalBody, limit)
|
n, err := io.CopyN(buf, originalBody, limit)
|
||||||
if err != nil || n == limit {
|
if (err != nil && err != io.EOF) || n == limit {
|
||||||
return bodyReadCloser{
|
return bodyReadCloser{
|
||||||
Reader: io.MultiReader(buf, originalBody),
|
Reader: io.MultiReader(buf, originalBody),
|
||||||
buf: buf,
|
buf: buf,
|
||||||
|
|
Loading…
Reference in a new issue