@@ -30,30 +30,22 @@ func (c HTTPClientConfig) String() string {
3030}
3131
3232func createHTTPClient (config HTTPClientConfig ) (* http.Client , error ) {
33-
3433 // Start with a copy of the default client
3534 httpClient := * http .DefaultClient
3635
37- // If no custom TLS configuration is needed, return the default client copy
38- if ! config .InsecureSkipVerify && config .RootCA == "" && config .RootCAFile == "" {
39- return & httpClient , nil
40- }
41-
4236 // Clone the default transport and cast to *http.Transport
4337 defaultTransport := http .DefaultTransport .(* http.Transport )
4438 transport := defaultTransport .Clone ()
4539
46- // Configure TLS settings
47- tlsConfig := & tls.Config {
48- InsecureSkipVerify : config .InsecureSkipVerify ,
40+ // Load system cert pool to respect env.SSL_CERT_DIR, env.SSL_CERT_FILE
41+ rootCAs , err := x509 .SystemCertPool ()
42+ if err != nil {
43+ return nil , fmt .Errorf ("failed to load system cert pool: %w" , err )
4944 }
5045
5146 // Set RootCAs if provided
5247 // Load root CA certificates from both string and file if defined
5348 if config .RootCA != "" || config .RootCAFile != "" {
54-
55- rootCAs := x509 .NewCertPool ()
56-
5749 // Add certificates from PEM string if provided
5850 if config .RootCA != "" {
5951 if ok := rootCAs .AppendCertsFromPEM ([]byte (config .RootCA )); ! ok {
@@ -72,12 +64,13 @@ func createHTTPClient(config HTTPClientConfig) (*http.Client, error) {
7264 return nil , fmt .Errorf ("failed to append CA certificate from file" )
7365 }
7466 }
75-
76- tlsConfig .RootCAs = rootCAs
7767 }
7868
7969 // Apply the custom TLS config to the cloned transport
80- transport .TLSClientConfig = tlsConfig
70+ transport .TLSClientConfig = & tls.Config {
71+ InsecureSkipVerify : config .InsecureSkipVerify ,
72+ RootCAs : rootCAs ,
73+ }
8174
8275 // Use the modified transport in our client copy
8376 httpClient .Transport = transport
0 commit comments