Merge pull request #1016 from bamarni/issue-1008

Set a NopCloser request body with retry middleware
This commit is contained in:
Emile Vauge 2017-02-02 19:13:43 +01:00 committed by GitHub
commit d0e2349dfd

View file

@ -3,6 +3,7 @@ package middlewares
import ( import (
"bufio" "bufio"
"bytes" "bytes"
"io/ioutil"
"net" "net"
"net/http" "net/http"
@ -32,6 +33,13 @@ func NewRetry(attempts int, next http.Handler) *Retry {
} }
func (retry *Retry) ServeHTTP(rw http.ResponseWriter, r *http.Request) { func (retry *Retry) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
// if we might make multiple attempts, swap the body for an ioutil.NopCloser
// cf https://github.com/containous/traefik/issues/1008
if retry.attempts > 1 {
body := r.Body
defer body.Close()
r.Body = ioutil.NopCloser(body)
}
attempts := 1 attempts := 1
for { for {
recorder := NewRecorder() recorder := NewRecorder()