NewIsolatedHTTPClient returns a test client with its own transport. Closing idle connections at test cleanup must not close http.DefaultTransport while another parallel test is using it.
(serverURL *url.URL)
| 687 | // Closing idle connections at test cleanup must not close http.DefaultTransport |
| 688 | // while another parallel test is using it. |
| 689 | func NewIsolatedHTTPClient(serverURL *url.URL) *http.Client { |
| 690 | transport := &http.Transport{Proxy: http.ProxyFromEnvironment} |
| 691 | if defaultTransport, ok := http.DefaultTransport.(*http.Transport); ok { |
| 692 | transport = defaultTransport.Clone() |
| 693 | } |
| 694 | if serverURL == nil || serverURL.Scheme != "https" { |
| 695 | transport.TLSClientConfig = nil |
| 696 | return &http.Client{Transport: transport} |
| 697 | } |
| 698 | if transport.TLSClientConfig == nil { |
| 699 | transport.TLSClientConfig = &tls.Config{MinVersion: tls.VersionTLS12} |
| 700 | } |
| 701 | if transport.TLSClientConfig.MinVersion == 0 { |
| 702 | transport.TLSClientConfig.MinVersion = tls.VersionTLS12 |
| 703 | } |
| 704 | //nolint:gosec // The coderdtest server uses test-only TLS certificates. |
| 705 | transport.TLSClientConfig.InsecureSkipVerify = true |
| 706 | return &http.Client{Transport: transport} |
| 707 | } |
| 708 | |
| 709 | // newHTTPClientWithTransportFrom returns a fresh client that shares the base |
| 710 | // transport without sharing mutable per-client state like CheckRedirect. |