| 843 | } |
| 844 | |
| 845 | func newHTTPTransport(tlsConfig *tls.Config) (http.RoundTripper, error) { |
| 846 | defaultTransport, ok := http.DefaultTransport.(*http.Transport) |
| 847 | if !ok { |
| 848 | if tlsConfig != nil { |
| 849 | return nil, xerrors.New("cannot apply TLS config: http.DefaultTransport is not *http.Transport") |
| 850 | } |
| 851 | return http.DefaultTransport, nil |
| 852 | } |
| 853 | |
| 854 | // Clone http.DefaultTransport for each CLI client. Parallel tests and |
| 855 | // embedded callers may close idle connections on their own clients, and |
| 856 | // sharing the process-global transport can interrupt in-flight requests. |
| 857 | transport := defaultTransport.Clone() |
| 858 | if tlsConfig != nil { |
| 859 | transport.TLSClientConfig = tlsConfig |
| 860 | } |
| 861 | return transport, nil |
| 862 | } |
| 863 | |
| 864 | func (r *RootCmd) createUnauthenticatedClient(ctx context.Context, serverURL *url.URL, inv *serpent.Invocation) (*codersdk.Client, error) { |
| 865 | // Load TLS config for login and other unauthenticated requests |