Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion coderd/notifications/dispatch/webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"text/template"
Expand Down Expand Up @@ -39,7 +40,22 @@ type WebhookPayload struct {
}

func NewWebhookHandler(cfg codersdk.NotificationsWebhookConfig, log slog.Logger) *WebhookHandler {
return &WebhookHandler{cfg: cfg, log: log, cl: &http.Client{}}
// Create a new transport in favor of reusing the default, since other http clients may interfere.
// http.Transport maintains its own connection pool, and we want to avoid cross-contamination.
var rt http.RoundTripper

def := http.DefaultTransport
t, ok := def.(*http.Transport)
if !ok {
// The API has changed (very unlikely), so let's use the default transport (previous behavior) and log.
log.Warn(context.Background(), "failed to clone default HTTP transport, unexpected type", slog.F("type", fmt.Sprintf("%T", def)))
rt = def
} else {
// Clone the transport's exported fields, but not its connection pool.
rt = t.Clone()
}

return &WebhookHandler{cfg: cfg, log: log, cl: &http.Client{Transport: rt}}
}

func (w *WebhookHandler) Dispatcher(payload types.MessagePayload, titleMarkdown, bodyMarkdown string, _ template.FuncMap) (DeliveryFunc, error) {
Expand Down
2 changes: 1 addition & 1 deletion coderd/notifications/dispatch/webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ func TestWebhook(t *testing.T) {
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
tc.serverFn(msgID, w, r)
}))
defer server.Close()
t.Cleanup(server.Close)

endpoint, err = url.Parse(server.URL)
require.NoError(t, err)
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy