MCPcopy Create free account
hub / github.com/Unpackerr/unpackerr / send

Method send

pkg/unpackerr/webhook.go:198–221  ·  view source on GitHub ↗
(ctx context.Context, body io.Reader)

Source from the content-addressed store, hash-verified

196}
197
198func (w *WebhookConfig) send(ctx context.Context, body io.Reader) ([]byte, error) {
199 req, err := http.NewRequestWithContext(ctx, http.MethodPost, w.URL, body)
200 if err != nil {
201 return nil, fmt.Errorf("creating request: %w", err)
202 }
203
204 req.Header.Set("Content-Type", w.CType)
205
206 res, err := w.client.Do(req)
207 if err != nil {
208 return nil, fmt.Errorf("POSTing payload: %w", err)
209 }
210 defer res.Body.Close()
211
212 // The error is mostly ignored because we don't care about the body.
213 // Read it in to avoid a memopry leak. Used in the if-stanza below.
214 reply, _ := io.ReadAll(res.Body)
215
216 if res.StatusCode < http.StatusOK || res.StatusCode > http.StatusNoContent {
217 return nil, fmt.Errorf("%w (%s): %s", ErrInvalidStatus, res.Status, reply)
218 }
219
220 return reply, nil
221}
222
223func (u *Unpackerr) validateWebhook() error { //nolint:cyclop
224 for idx := range u.Webhook {

Callers 1

SendMethod · 0.95

Calls 1

ErrorfMethod · 0.65

Tested by

no test coverage detected