Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: use new http transport for webhook handler#19462

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
dannykopping merged 1 commit intomainfromdk/flake-919
Aug 21, 2025
Merged
Show file tree
Hide file tree
Changes fromall 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 deletioncoderd/notifications/dispatch/webhook.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -5,6 +5,7 @@ import (
"context"
"encoding/json"
"errors"
"fmt"
"io"
"net/http"
"text/template"
Expand DownExpand 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 deletioncoderd/notifications/dispatch/webhook_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff 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)
}))
deferserver.Close()
t.Cleanup(server.Close)

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

[8]ページ先頭

©2009-2025 Movatter.jp