callscore: keep a replaced default transport rather than panic
38ad0b7's internal/callstest TestMain installs keymailtest's transport as http.DefaultTransport; safeClient asserted *http.Transport and panicked, so make native-browser died in TestNativeBrowserAppLink before running anything. It clones the default only when it is an *http.Transport.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+11
−3
callscore/transport.go+11 −3
CI passed — run details
diff --git a/callscore/transport.go b/callscore/transport.go| index a953645..e64b3d7 100644 |
| --- a/callscore/transport.go |
| +++ b/callscore/transport.go |
| @@ -74,9 +74,17 @@ func safeClient(client *http.Client) (*http.Client, error) { |
| } |
| safe := *client |
| if safe.Transport == nil { |
| - transport := http.DefaultTransport.(*http.Transport).Clone() |
| - transport.ResponseHeaderTimeout = 15 * time.Second |
| - safe.Transport = transport |
| + // The default transport, with a deadline on the response's |
| + // headers. A process that has replaced it (internal/callstest's |
| + // TestMain installs keymailtest's, which answers DNS in-process) |
| + // keeps its own: asserting *http.Transport panicked there. |
| + if base, ok := http.DefaultTransport.(*http.Transport); ok { |
| + transport := base.Clone() |
| + transport.ResponseHeaderTimeout = 15 * time.Second |
| + safe.Transport = transport |
| + } else { |
| + safe.Transport = http.DefaultTransport |
| + } |
| } |
| safe.CheckRedirect = func(*http.Request, []*http.Request) error { return http.ErrUseLastResponse } |
| safe.Timeout = 0 // streams live for five minutes; individual calls have deadlines |