Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Commit 39a3370

Browse files
committed
Add methods to set root CAs for Transport
1 parent 1452f63 commit 39a3370

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

client.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"compress/zlib"
77
"crypto/rand"
88
"crypto/tls"
9+
"crypto/x509"
910
"encoding/base64"
1011
"encoding/hex"
1112
"encoding/json"
@@ -317,14 +318,31 @@ func newTransport() Transport {
317318
} else {
318319
t.Client = &http.Client{
319320
Transport: &http.Transport{
320-
Proxy: http.ProxyFromEnvironment,
321+
Proxy: http.ProxyFromEnvironment,
321322
TLSClientConfig: &tls.Config{RootCAs: rootCAs},
322323
},
323324
}
324325
}
325326
return t
326327
}
327328

329+
// SetRootCAs sets the root CAs for the default *Client instance
330+
func SetRootCAs(CAs *x509.CertPool) {
331+
DefaultClient.SetRootCAs(CAs)
332+
}
333+
334+
// SetRootCAs sets the root CAs for this client instance
335+
func (client *Client) SetRootCAs(CAs *x509.CertPool) {
336+
t := &HTTPTransport{}
337+
t.Client = &http.Client{
338+
Transport: &http.Transport{
339+
Proxy: http.ProxyFromEnvironment,
340+
TLSClientConfig: &tls.Config{RootCAs: CAs},
341+
},
342+
}
343+
client.Transport = t
344+
}
345+
328346
func newClient(tags map[string]string) *Client {
329347
client := &Client{
330348
Transport: newTransport(),

0 commit comments

Comments
 (0)