From 4fe96f94b78cf0ddd170f894fa83794a40321a01 Mon Sep 17 00:00:00 2001 From: Giorgos Komninos Date: Mon, 9 May 2022 20:56:54 +0300 Subject: [PATCH] webhooks: discarding body after http requests in order to allow reusing the underlying connection --- webhooks.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/webhooks.go b/webhooks.go index 15097f03e..e7c12d348 100644 --- a/webhooks.go +++ b/webhooks.go @@ -5,6 +5,8 @@ import ( "context" "encoding/json" "fmt" + "io" + "io/ioutil" "net/http" ) @@ -51,7 +53,10 @@ func PostWebhookCustomHTTPContext(ctx context.Context, url string, httpClient *h if err != nil { return fmt.Errorf("failed to post webhook: %w", err) } - defer resp.Body.Close() + defer func() { + io.Copy(ioutil.Discard, resp.Body) + resp.Body.Close() + }() return checkStatusCode(resp, discard{}) }