Merge pull request #1016 from bamarni/issue-1008
Set a NopCloser request body with retry middleware
This commit is contained in:
commit
d0e2349dfd
1 changed files with 8 additions and 0 deletions
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue