From 3abd0dc82a3cb40e2fc4da42a2d9659570da9507 Mon Sep 17 00:00:00 2001 From: Jesse Peterson Date: Tue, 2 May 2023 08:49:00 -0700 Subject: [PATCH] Shore up HTTP client body closes, ioutil->io package --- cmd/nano2nano/main.go | 4 ++-- service/microwebhook/post.go | 1 + service/nanomdm/dm.go | 6 +++--- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/cmd/nano2nano/main.go b/cmd/nano2nano/main.go index 7327397..6e88593 100644 --- a/cmd/nano2nano/main.go +++ b/cmd/nano2nano/main.go @@ -6,7 +6,7 @@ import ( "errors" "flag" "fmt" - "io/ioutil" + "io" stdlog "log" "net/http" @@ -119,7 +119,7 @@ func httpPut(client *http.Client, url string, key string, sendBytes []byte) erro return err } defer res.Body.Close() - _, err = ioutil.ReadAll(res.Body) + _, err = io.ReadAll(res.Body) if err != nil { return err } diff --git a/service/microwebhook/post.go b/service/microwebhook/post.go index 538ec55..6a48186 100644 --- a/service/microwebhook/post.go +++ b/service/microwebhook/post.go @@ -27,6 +27,7 @@ func postWebhookEvent( if err != nil { return err } + defer resp.Body.Close() if resp.StatusCode != 200 { return fmt.Errorf("unexpected HTTP status %d %s", resp.StatusCode, resp.Status) } diff --git a/service/nanomdm/dm.go b/service/nanomdm/dm.go index 06d75c5..bdf6036 100644 --- a/service/nanomdm/dm.go +++ b/service/nanomdm/dm.go @@ -4,7 +4,7 @@ import ( "bytes" "errors" "fmt" - "io/ioutil" + "io" "net/http" "net/url" @@ -51,11 +51,11 @@ func (c *DeclarativeManagementHTTPCaller) DeclarativeManagement(r *mdm.Request, if err != nil { return nil, err } - bodyBytes, err := ioutil.ReadAll(resp.Body) + defer resp.Body.Close() + bodyBytes, err := io.ReadAll(resp.Body) if err != nil { return nil, err } - defer resp.Body.Close() if resp.StatusCode != 200 { return bodyBytes, service.NewHTTPStatusError( resp.StatusCode,