From a256e81503a1c423b42d50dd60846a5e99a8961c Mon Sep 17 00:00:00 2001 From: zhayt Date: Sat, 16 Mar 2024 13:35:33 +0500 Subject: [PATCH 1/2] fix: goroutine leaks. And don't execute defer in for loops --- lib/ocsp.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/ocsp.go b/lib/ocsp.go index 0fa1929..8cc75c6 100644 --- a/lib/ocsp.go +++ b/lib/ocsp.go @@ -149,7 +149,7 @@ func fetchOCSP(cert, issuer *x509.Certificate) ([]byte, error) { } body, err := io.ReadAll(resp.Body) - defer resp.Body.Close() + resp.Body.Close() if err != nil { lastError = err continue From 5977fa2d82c76a6a1c2746bc0b0cc5651928ecfc Mon Sep 17 00:00:00 2001 From: zhayt Date: Sat, 16 Mar 2024 13:38:30 +0500 Subject: [PATCH 2/2] refactor: use the GET and POST constants of the http library --- lib/ocsp.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/ocsp.go b/lib/ocsp.go index 8cc75c6..ef3deb8 100644 --- a/lib/ocsp.go +++ b/lib/ocsp.go @@ -162,7 +162,7 @@ func fetchOCSP(cert, issuer *x509.Certificate) ([]byte, error) { } func buildOCSPwithPOST(server string, encoded []byte) (*http.Request, error) { - req, err := http.NewRequest("POST", server, nil) + req, err := http.NewRequest(http.MethodPost, server, nil) if err != nil { return nil, err } @@ -179,7 +179,7 @@ func buildOCSPwithGET(server string, encoded []byte) (*http.Request, error) { // GET {url}/{url-encoding of base-64 encoding of the DER encoding of the OCSPRequest} url := fmt.Sprintf("%s/%s", server, base64.StdEncoding.EncodeToString(encoded)) - req, err := http.NewRequest("GET", url, nil) + req, err := http.NewRequest(http.MethodGet, url, nil) if err != nil { return nil, err }