...
1
2
3
4
5
6
7 package resty
8
9 import (
10 "net"
11 "net/http"
12 "runtime"
13 "time"
14 )
15
16 func createTransport(localAddr net.Addr) *http.Transport {
17 dialer := &net.Dialer{
18 Timeout: 30 * time.Second,
19 KeepAlive: 30 * time.Second,
20 DualStack: true,
21 }
22 if localAddr != nil {
23 dialer.LocalAddr = localAddr
24 }
25 return &http.Transport{
26 Proxy: http.ProxyFromEnvironment,
27 DialContext: dialer.DialContext,
28 ForceAttemptHTTP2: true,
29 MaxIdleConns: 100,
30 IdleConnTimeout: 90 * time.Second,
31 TLSHandshakeTimeout: 10 * time.Second,
32 ExpectContinueTimeout: 1 * time.Second,
33 MaxIdleConnsPerHost: runtime.GOMAXPROCS(0) + 1,
34 }
35 }
36
View as plain text