MCPcopy Index your code
hub / github.com/coder/coder / NewWebhookHandler

Function NewWebhookHandler

coderd/notifications/dispatch/webhook.go:41–58  ·  view source on GitHub ↗
(cfg codersdk.NotificationsWebhookConfig, log slog.Logger)

Source from the content-addressed store, hash-verified

39}
40
41func NewWebhookHandler(cfg codersdk.NotificationsWebhookConfig, log slog.Logger) *WebhookHandler {
42 // Create a new transport in favor of reusing the default, since other http clients may interfere.
43 // http.Transport maintains its own connection pool, and we want to avoid cross-contamination.
44 var rt http.RoundTripper
45
46 def := http.DefaultTransport
47 t, ok := def.(*http.Transport)
48 if !ok {
49 // The API has changed (very unlikely), so let's use the default transport (previous behavior) and log.
50 log.Warn(context.Background(), "failed to clone default HTTP transport, unexpected type", slog.F("type", fmt.Sprintf("%T", def)))
51 rt = def
52 } else {
53 // Clone the transport's exported fields, but not its connection pool.
54 rt = t.Clone()
55 }
56
57 return &WebhookHandler{cfg: cfg, log: log, cl: &http.Client{Transport: rt}}
58}
59
60func (w *WebhookHandler) Dispatcher(payload types.MessagePayload, titleMarkdown, bodyMarkdown string, _ template.FuncMap) (DeliveryFunc, error) {
61 if w.cfg.Endpoint.String() == "" {

Callers 3

TestRetriesFunction · 0.92
defaultHandlersFunction · 0.92
TestWebhookFunction · 0.92

Calls 1

CloneMethod · 0.45

Tested by 2

TestRetriesFunction · 0.74
TestWebhookFunction · 0.74