From 3f044c48fad3fbf7f2e70a28afc7fc2ddb3af85d Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Tue, 23 Oct 2018 10:10:04 +0200 Subject: [PATCH] Nil request body with retry --- healthcheck/healthcheck.go | 2 +- middlewares/auth/forward.go | 2 +- middlewares/errorpages/error_pages.go | 2 +- middlewares/retry.go | 3 +++ 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/healthcheck/healthcheck.go b/healthcheck/healthcheck.go index 8a6e9bba0..222c6328a 100644 --- a/healthcheck/healthcheck.go +++ b/healthcheck/healthcheck.go @@ -71,7 +71,7 @@ func (b *BackendConfig) newRequest(serverURL *url.URL) (*http.Request, error) { 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 diff --git a/middlewares/auth/forward.go b/middlewares/auth/forward.go index 5292c282c..7afc767c6 100644 --- a/middlewares/auth/forward.go +++ b/middlewares/auth/forward.go @@ -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) if err != nil { tracing.SetErrorAndDebugLog(r, "Error calling %s. Cause %s", config.Address, err) diff --git a/middlewares/errorpages/error_pages.go b/middlewares/errorpages/error_pages.go index 9fbe84706..10f241bb4 100644 --- a/middlewares/errorpages/error_pages.go +++ b/middlewares/errorpages/error_pages.go @@ -120,7 +120,7 @@ func newRequest(baseURL string) (*http.Request, error) { 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 { return nil, fmt.Errorf("error pages: error when create query: %v", err) } diff --git a/middlewares/retry.go b/middlewares/retry.go index ed9f339d9..79a05d900 100644 --- a/middlewares/retry.go +++ b/middlewares/retry.go @@ -35,6 +35,9 @@ func (retry *Retry) ServeHTTP(rw http.ResponseWriter, r *http.Request) { // cf https://github.com/containous/traefik/issues/1008 if retry.attempts > 1 { body := r.Body + if body == nil { + body = http.NoBody + } defer body.Close() r.Body = ioutil.NopCloser(body) }