From 39a3370c11d2fc48f197e1ffbac1a59d18977bd2 Mon Sep 17 00:00:00 2001 From: Liu Yang Date: Wed, 27 Sep 2017 18:00:28 +0900 Subject: [PATCH] Add methods to set root CAs for Transport --- client.go | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 9d43641..ce4a728 100644 --- a/client.go +++ b/client.go @@ -6,6 +6,7 @@ import ( "compress/zlib" "crypto/rand" "crypto/tls" + "crypto/x509" "encoding/base64" "encoding/hex" "encoding/json" @@ -317,7 +318,7 @@ func newTransport() Transport { } else { t.Client = &http.Client{ Transport: &http.Transport{ - Proxy: http.ProxyFromEnvironment, + Proxy: http.ProxyFromEnvironment, TLSClientConfig: &tls.Config{RootCAs: rootCAs}, }, } @@ -325,6 +326,23 @@ func newTransport() Transport { 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(),