mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 14:13:48 +03:00
reverseproxy: Reuse buffered request body even if partially drained
Previous commit only works when the backends don't read any of the body first.
This commit is contained in:
parent
613d544a47
commit
d93e027e01
1 changed files with 9 additions and 0 deletions
|
@ -439,6 +439,15 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyht
|
||||||
var proxyErr error
|
var proxyErr error
|
||||||
var retries int
|
var retries int
|
||||||
for {
|
for {
|
||||||
|
// if the request body was buffered (and only the entire body, hence no body
|
||||||
|
// set to read from after the buffer), make reading from the body idempotent
|
||||||
|
// and reusable, so if a backend partially or fully reads the body but then
|
||||||
|
// produces an error, the request can be repeated to the next backend with
|
||||||
|
// the full body (retries should only happen for idempotent requests) (see #6259)
|
||||||
|
if reqBodyBuf, ok := r.Body.(bodyReadCloser); ok && reqBodyBuf.body == nil {
|
||||||
|
r.Body = io.NopCloser(bytes.NewReader(reqBodyBuf.buf.Bytes()))
|
||||||
|
}
|
||||||
|
|
||||||
var done bool
|
var done bool
|
||||||
done, proxyErr = h.proxyLoopIteration(clonedReq, r, w, proxyErr, start, retries, repl, reqHeader, reqHost, next)
|
done, proxyErr = h.proxyLoopIteration(clonedReq, r, w, proxyErr, start, retries, repl, reqHeader, reqHost, next)
|
||||||
if done {
|
if done {
|
||||||
|
|
Loading…
Reference in a new issue