-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient.go
executable file
·59 lines (49 loc) · 1.54 KB
/
client.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
47
48
49
50
51
52
53
54
55
56
57
58
59
package outgoing
import (
"context"
"net"
"net/http"
"time"
"github.com/chongyangshi/wylis/config"
"github.com/monzo/slog"
"github.com/monzo/typhon"
)
var (
outgoingInterval time.Duration
client typhon.Service
)
func initTyphonClient(ctx context.Context) error {
var err error
outgoingInterval, err = time.ParseDuration(config.ConfigOutgoingInterval)
if err != nil {
slog.Error(ctx, "Error parsing outgoing interval from environmental config: %v", err)
return err
}
timeOut, err := time.ParseDuration(config.ConfigOutgoingTimeout)
if err != nil {
slog.Error(ctx, "Error parsing timeout interval from environmental config: %v", err)
return err
}
slog.Info(ctx, "Outgoing request interval: %v, outgoing request timeout: %v.", outgoingInterval, timeOut)
// Do not reuse HTTP connections, this is less efficient but ensures that
// middlebox kernel always observes new TCP connections going through,
// keeping routing fresh.
roundTripper := &http.Transport{
DisableKeepAlives: true,
DisableCompression: false,
DialContext: (&net.Dialer{
Timeout: timeOut,
KeepAlive: -1 * time.Second, // Disabled
DualStack: true,
}).DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
MaxIdleConnsPerHost: 10,
IdleConnTimeout: 60 * time.Second,
TLSHandshakeTimeout: timeOut,
ResponseHeaderTimeout: timeOut,
ExpectContinueTimeout: 1 * time.Second,
}
client = typhon.HttpService(roundTripper).Filter(typhon.ExpirationFilter).Filter(typhon.H2cFilter).Filter(typhon.ErrorFilter)
return nil
}