Skip to content

Commit 3cc617f

Browse files
authored
Merge pull request #1164 from grongor/dont-use-default-http-client
Allow users to use custom HTTP client
2 parents 23b638f + 7a59a7d commit 3cc617f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

bundler/bundler.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ import (
3232
// When unspecified, downloaded intermediates are not saved.
3333
var IntermediateStash string
3434

35+
// HTTPClient is an instance of http.Client that will be used for all HTTP requests.
36+
var HTTPClient = http.DefaultClient
37+
3538
// BundleFlavor is named optimization strategy on certificate chain selection when bundling.
3639
type BundleFlavor string
3740

@@ -333,7 +336,7 @@ type fetchedIntermediate struct {
333336
func fetchRemoteCertificate(certURL string) (fi *fetchedIntermediate, err error) {
334337
log.Debugf("fetching remote certificate: %s", certURL)
335338
var resp *http.Response
336-
resp, err = http.Get(certURL)
339+
resp, err = HTTPClient.Get(certURL)
337340
if err != nil {
338341
log.Debugf("failed HTTP get: %v", err)
339342
return

revoke/revoke.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ import (
2525
"github.com/cloudflare/cfssl/log"
2626
)
2727

28+
// HTTPClient is an instance of http.Client that will be used for all HTTP requests.
29+
var HTTPClient = http.DefaultClient
30+
2831
// HardFail determines whether the failure to check the revocation
2932
// status of a certificate (i.e. due to network failure) causes
3033
// verification to fail (a hard failure).
@@ -99,7 +102,7 @@ func revCheck(cert *x509.Certificate) (revoked, ok bool, err error) {
99102

100103
// fetchCRL fetches and parses a CRL.
101104
func fetchCRL(url string) (*pkix.CertificateList, error) {
102-
resp, err := http.Get(url)
105+
resp, err := HTTPClient.Get(url)
103106
if err != nil {
104107
return nil, err
105108
} else if resp.StatusCode >= 300 {
@@ -205,7 +208,7 @@ func VerifyCertificateError(cert *x509.Certificate) (revoked, ok bool, err error
205208
}
206209

207210
func fetchRemote(url string) (*x509.Certificate, error) {
208-
resp, err := http.Get(url)
211+
resp, err := HTTPClient.Get(url)
209212
if err != nil {
210213
return nil, err
211214
}
@@ -278,10 +281,10 @@ func sendOCSPRequest(server string, req []byte, leaf, issuer *x509.Certificate)
278281
var err error
279282
if len(req) > 256 {
280283
buf := bytes.NewBuffer(req)
281-
resp, err = http.Post(server, "application/ocsp-request", buf)
284+
resp, err = HTTPClient.Post(server, "application/ocsp-request", buf)
282285
} else {
283286
reqURL := server + "/" + neturl.QueryEscape(base64.StdEncoding.EncodeToString(req))
284-
resp, err = http.Get(reqURL)
287+
resp, err = HTTPClient.Get(reqURL)
285288
}
286289

287290
if err != nil {

0 commit comments

Comments
 (0)