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

Function NewIsolatedHTTPClient

coderd/coderdtest/coderdtest.go:689–707  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

687// Closing idle connections at test cleanup must not close http.DefaultTransport
688// while another parallel test is using it.
689func 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.

Callers 12

TestDERPForceWebSocketsFunction · 0.92
TestWorkspaceAgentFunction · 0.92
TestTemplateEditFunction · 0.92
TestDERPHeadersFunction · 0.92
NewWithAPIFunction · 0.85

Calls 1

CloneMethod · 0.45

Tested by 10

TestDERPForceWebSocketsFunction · 0.74
TestWorkspaceAgentFunction · 0.74
TestTemplateEditFunction · 0.74
TestDERPHeadersFunction · 0.74