-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.go
More file actions
53 lines (50 loc) · 1.34 KB
/
client.go
File metadata and controls
53 lines (50 loc) · 1.34 KB
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
47
48
49
50
51
52
53
package httpcli
import (
"context"
"crypto/tls"
"net"
"net/http"
"time"
)
const (
defaultDialTimeout = 10 * time.Second
keepAliveInterval = 30 * time.Second
)
var (
gTransport = &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: false,
},
ResponseHeaderTimeout: 2 * time.Minute,
DisableCompression: true,
DisableKeepAlives: false,
IdleConnTimeout: 2 * time.Minute,
MaxIdleConns: 4,
MaxIdleConnsPerHost: 2,
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
dialer := &net.Dialer{Timeout: defaultDialTimeout, KeepAlive: keepAliveInterval}
return dialer.DialContext(ctx, network, addr)
},
}
gTransportSkipVerify = &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
},
ResponseHeaderTimeout: 2 * time.Minute,
DisableCompression: true,
DisableKeepAlives: false,
IdleConnTimeout: 2 * time.Minute,
MaxIdleConns: 4,
MaxIdleConnsPerHost: 2,
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
dialer := &net.Dialer{Timeout: defaultDialTimeout, KeepAlive: keepAliveInterval}
return dialer.DialContext(ctx, network, addr)
},
}
gHTTPClient = &http.Client{
Transport: gTransport,
}
gHTTPClientSkipVerify = &http.Client{
Transport: gTransportSkipVerify,
}
)