httpd: move the check connection middleware before the logger middleware

Fixes #543
This commit is contained in:
Nicola Murino 2021-09-19 08:22:40 +02:00
parent 7d20c6b50d
commit c69c27f586
No known key found for this signature in database
GPG key ID: 2F1FB59433D5A8CB
2 changed files with 17 additions and 5 deletions

View file

@ -190,7 +190,10 @@ func Get(url string) (*http.Response, error) {
return nil, err
}
addHeaders(req, url)
return GetHTTPClient().Do(req)
client := GetHTTPClient()
defer client.CloseIdleConnections()
return client.Do(req)
}
// Post issues a POST to the specified URL
@ -201,7 +204,10 @@ func Post(url string, contentType string, body io.Reader) (*http.Response, error
}
req.Header.Set("Content-Type", contentType)
addHeaders(req, url)
return GetHTTPClient().Do(req)
client := GetHTTPClient()
defer client.CloseIdleConnections()
return client.Do(req)
}
// RetryableGet issues a GET to the specified URL using the retryable client
@ -211,7 +217,10 @@ func RetryableGet(url string) (*http.Response, error) {
return nil, err
}
addHeadersToRetryableReq(req, url)
return GetRetraybleHTTPClient().Do(req)
client := GetRetraybleHTTPClient()
defer client.HTTPClient.CloseIdleConnections()
return client.Do(req)
}
// RetryablePost issues a POST to the specified URL using the retryable client
@ -222,7 +231,10 @@ func RetryablePost(url string, contentType string, body io.Reader) (*http.Respon
}
req.Header.Set("Content-Type", contentType)
addHeadersToRetryableReq(req, url)
return GetRetraybleHTTPClient().Do(req)
client := GetRetraybleHTTPClient()
defer client.HTTPClient.CloseIdleConnections()
return client.Do(req)
}
func addHeaders(req *http.Request, url string) {

View file

@ -530,9 +530,9 @@ func (s *httpdServer) initializeRouter() {
s.router = chi.NewRouter()
s.router.Use(middleware.RequestID)
s.router.Use(s.checkConnection)
s.router.Use(logger.NewStructuredLogger(logger.GetLogger()))
s.router.Use(recoverer)
s.router.Use(s.checkConnection)
s.router.Use(middleware.GetHead)
s.router.Use(middleware.StripSlashes)