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

Commit

Permalink
Add methods to set root CAs for Transport
Browse files Browse the repository at this point in the history
  • Loading branch information
LeonLiuY committed Sep 27, 2017
1 parent 1452f63 commit 39a3370
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"compress/zlib"
"crypto/rand"
"crypto/tls"
"crypto/x509"
"encoding/base64"
"encoding/hex"
"encoding/json"
Expand Down Expand Up @@ -317,14 +318,31 @@ func newTransport() Transport {
} else {
t.Client = &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: &tls.Config{RootCAs: rootCAs},
},
}
}
return t
}

// SetRootCAs sets the root CAs for the default *Client instance
func SetRootCAs(CAs *x509.CertPool) {
DefaultClient.SetRootCAs(CAs)
}

// SetRootCAs sets the root CAs for this client instance
func (client *Client) SetRootCAs(CAs *x509.CertPool) {
t := &HTTPTransport{}
t.Client = &http.Client{
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
TLSClientConfig: &tls.Config{RootCAs: CAs},
},
}
client.Transport = t
}

func newClient(tags map[string]string) *Client {
client := &Client{
Transport: newTransport(),
Expand Down

0 comments on commit 39a3370

Please sign in to comment.