diff --git a/httpclient/httpclient.go b/httpclient/httpclient.go index c4dd0cb4..c94bd4f7 100644 --- a/httpclient/httpclient.go +++ b/httpclient/httpclient.go @@ -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) { diff --git a/httpd/server.go b/httpd/server.go index d24fdda7..e2292353 100644 --- a/httpd/server.go +++ b/httpd/server.go @@ -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)