Browse Source

Add content type to request

Signed-off-by: jolheiser <john.olheiser@gmail.com>
main v0.0.3
jolheiser 7 months ago
parent
commit
2f590738ba
Signed by: jolheiser GPG Key ID: B853ADA5DA7BBF7A
  1. 2
      go.mod
  2. 7
      webhook.go
  3. 8
      webhook_test.go

2
go.mod

@ -1,3 +1,3 @@
module go.jolheiser.com/disco
go 1.15
go 1.16

7
webhook.go

@ -25,7 +25,12 @@ func (w *Webhook) Request(ctx context.Context, webhookURL string) (*http.Request
if err != nil {
return nil, err
}
return http.NewRequestWithContext(ctx, http.MethodPost, webhookURL, bytes.NewBuffer(payload))
req, err := http.NewRequestWithContext(ctx, http.MethodPost, webhookURL, bytes.NewBuffer(payload))
if err != nil {
return nil, err
}
req.Header.Set("Content-Type", "application/json")
return req, nil
}
// Send is a basic convenience for sending a Webhook

8
webhook_test.go

@ -1,6 +1,8 @@
package disco
import (
"context"
"io"
"os"
"testing"
)
@ -58,14 +60,16 @@ func TestWebhook(t *testing.T) {
},
}
resp, err := webhook.Send(u)
resp, err := webhook.Send(context.Background(), u)
if err != nil {
t.Log(err)
t.FailNow()
}
if resp.StatusCode != 204 {
t.Logf("Non-204 status returned: %d", resp.StatusCode)
respText, _ := io.ReadAll(resp.Body)
defer resp.Body.Close()
t.Logf("Non-204 status returned: %d\n%s", resp.StatusCode, respText)
t.FailNow()
}
}

Loading…
Cancel
Save