-
Notifications
You must be signed in to change notification settings - Fork 23
/
default_http_clients.go
46 lines (37 loc) · 985 Bytes
/
default_http_clients.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package httpclient
import (
"crypto/tls"
"crypto/x509"
"net"
"net/http"
"time"
)
var DefaultClient = CreateDefaultClientInsecureSkipVerify()
type Client interface {
Do(*http.Request) (*http.Response, error)
}
func CreateDefaultClient(certPool *x509.CertPool) *http.Client {
insecureSkipVerify := false
return createDefaultClient(insecureSkipVerify, certPool)
}
func CreateDefaultClientInsecureSkipVerify() *http.Client {
insecureSkipVerify := true
return createDefaultClient(insecureSkipVerify, nil)
}
func createDefaultClient(insecureSkipVerify bool, certPool *x509.CertPool) *http.Client {
return &http.Client{
Transport: &http.Transport{
TLSClientConfig: &tls.Config{
RootCAs: certPool,
InsecureSkipVerify: insecureSkipVerify,
},
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 0,
}).Dial,
TLSHandshakeTimeout: 30 * time.Second,
DisableKeepAlives: true,
},
}
}