closes the body properly on successful webhooks

this commit also adds a test docker container
for receiving alerting web hook requests
This commit is contained in:
bergquist
2018-12-27 13:16:58 +01:00
parent 8a976f5cb4
commit 24636da800
4 changed files with 41 additions and 1 deletions

View File

@@ -4,6 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io"
"io/ioutil"
"net"
"net/http"
@@ -69,11 +70,14 @@ func (ns *NotificationService) sendWebRequestSync(ctx context.Context, webhook *
return err
}
defer resp.Body.Close()
if resp.StatusCode/100 == 2 {
// flushing the body enables the transport to reuse the same connection
io.Copy(ioutil.Discard, resp.Body)
return nil
}
defer resp.Body.Close()
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err