Nil request body with retry

This commit is contained in:
Ludovic Fernandez 2018-10-23 10:10:04 +02:00 committed by Traefiker Bot
parent 37d8e32e0b
commit 3f044c48fa
4 changed files with 6 additions and 3 deletions

View file

@ -71,7 +71,7 @@ func (b *BackendConfig) newRequest(serverURL *url.URL) (*http.Request, error) {
u.Path += b.Path u.Path += b.Path
return http.NewRequest(http.MethodGet, u.String(), nil) return http.NewRequest(http.MethodGet, u.String(), http.NoBody)
} }
// this function adds additional http headers and hostname to http.request // this function adds additional http headers and hostname to http.request

View file

@ -40,7 +40,7 @@ func Forward(config *types.Forward, w http.ResponseWriter, r *http.Request, next
} }
} }
forwardReq, err := http.NewRequest(http.MethodGet, config.Address, nil) forwardReq, err := http.NewRequest(http.MethodGet, config.Address, http.NoBody)
tracing.LogRequest(tracing.GetSpan(r), forwardReq) tracing.LogRequest(tracing.GetSpan(r), forwardReq)
if err != nil { if err != nil {
tracing.SetErrorAndDebugLog(r, "Error calling %s. Cause %s", config.Address, err) tracing.SetErrorAndDebugLog(r, "Error calling %s. Cause %s", config.Address, err)

View file

@ -120,7 +120,7 @@ func newRequest(baseURL string) (*http.Request, error) {
return nil, fmt.Errorf("error pages: error when parse URL: %v", err) return nil, fmt.Errorf("error pages: error when parse URL: %v", err)
} }
req, err := http.NewRequest(http.MethodGet, u.String(), nil) req, err := http.NewRequest(http.MethodGet, u.String(), http.NoBody)
if err != nil { if err != nil {
return nil, fmt.Errorf("error pages: error when create query: %v", err) return nil, fmt.Errorf("error pages: error when create query: %v", err)
} }

View file

@ -35,6 +35,9 @@ func (retry *Retry) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
// cf https://github.com/containous/traefik/issues/1008 // cf https://github.com/containous/traefik/issues/1008
if retry.attempts > 1 { if retry.attempts > 1 {
body := r.Body body := r.Body
if body == nil {
body = http.NoBody
}
defer body.Close() defer body.Close()
r.Body = ioutil.NopCloser(body) r.Body = ioutil.NopCloser(body)
} }