@@ -12,10 +12,11 @@ import (
1212)
1313
1414var (
15- defaultConnectTimeout = config.CustomDuration {Duration : 30 * time .Second }
16- defaultTLSTimeout = config.CustomDuration {Duration : 10 * time .Second }
17- defaultTCPKeepAlive = config.CustomDuration {Duration : 30 * time .Second }
18- defaultKeepAliveTimeout = config.CustomDuration {Duration : 90 * time .Second }
15+ defaultHTTPConnectTimeout = config.CustomDuration {Duration : 30 * time .Second }
16+ defaultWarpRoutingConnectTimeout = config.CustomDuration {Duration : 5 * time .Second }
17+ defaultTLSTimeout = config.CustomDuration {Duration : 10 * time .Second }
18+ defaultTCPKeepAlive = config.CustomDuration {Duration : 30 * time .Second }
19+ defaultKeepAliveTimeout = config.CustomDuration {Duration : 90 * time .Second }
1920)
2021
2122const (
@@ -41,10 +42,44 @@ const (
4142 socksProxy = "socks"
4243)
4344
45+ type WarpRoutingConfig struct {
46+ Enabled bool `yaml:"enabled" json:"enabled"`
47+ ConnectTimeout config.CustomDuration `yaml:"connectTimeout" json:"connectTimeout,omitempty"`
48+ TCPKeepAlive config.CustomDuration `yaml:"tcpKeepAlive" json:"tcpKeepAlive,omitempty"`
49+ }
50+
51+ func NewWarpRoutingConfig (raw * config.WarpRoutingConfig ) WarpRoutingConfig {
52+ cfg := WarpRoutingConfig {
53+ Enabled : raw .Enabled ,
54+ ConnectTimeout : defaultWarpRoutingConnectTimeout ,
55+ TCPKeepAlive : defaultTCPKeepAlive ,
56+ }
57+ if raw .ConnectTimeout != nil {
58+ cfg .ConnectTimeout = * raw .ConnectTimeout
59+ }
60+ if raw .TCPKeepAlive != nil {
61+ cfg .TCPKeepAlive = * raw .TCPKeepAlive
62+ }
63+ return cfg
64+ }
65+
66+ func (c * WarpRoutingConfig ) RawConfig () config.WarpRoutingConfig {
67+ raw := config.WarpRoutingConfig {
68+ Enabled : c .Enabled ,
69+ }
70+ if c .ConnectTimeout .Duration != defaultWarpRoutingConnectTimeout .Duration {
71+ raw .ConnectTimeout = & c .ConnectTimeout
72+ }
73+ if c .TCPKeepAlive .Duration != defaultTCPKeepAlive .Duration {
74+ raw .TCPKeepAlive = & c .TCPKeepAlive
75+ }
76+ return raw
77+ }
78+
4479// RemoteConfig models ingress settings that can be managed remotely, for example through the dashboard.
4580type RemoteConfig struct {
4681 Ingress Ingress
47- WarpRouting config. WarpRoutingConfig
82+ WarpRouting WarpRoutingConfig
4883}
4984
5085type RemoteConfigJSON struct {
@@ -72,18 +107,18 @@ func (rc *RemoteConfig) UnmarshalJSON(b []byte) error {
72107 }
73108
74109 rc .Ingress = ingress
75- rc .WarpRouting = rawConfig .WarpRouting
110+ rc .WarpRouting = NewWarpRoutingConfig ( & rawConfig .WarpRouting )
76111
77112 return nil
78113}
79114
80115func originRequestFromSingeRule (c * cli.Context ) OriginRequestConfig {
81- var connectTimeout config. CustomDuration = defaultConnectTimeout
82- var tlsTimeout config. CustomDuration = defaultTLSTimeout
83- var tcpKeepAlive config. CustomDuration = defaultTCPKeepAlive
116+ var connectTimeout = defaultHTTPConnectTimeout
117+ var tlsTimeout = defaultTLSTimeout
118+ var tcpKeepAlive = defaultTCPKeepAlive
84119 var noHappyEyeballs bool
85- var keepAliveConnections int = defaultKeepAliveConnections
86- var keepAliveTimeout config. CustomDuration = defaultKeepAliveTimeout
120+ var keepAliveConnections = defaultKeepAliveConnections
121+ var keepAliveTimeout = defaultKeepAliveTimeout
87122 var httpHostHeader string
88123 var originServerName string
89124 var caPool string
@@ -160,7 +195,7 @@ func originRequestFromSingeRule(c *cli.Context) OriginRequestConfig {
160195
161196func originRequestFromConfig (c config.OriginRequestConfig ) OriginRequestConfig {
162197 out := OriginRequestConfig {
163- ConnectTimeout : defaultConnectTimeout ,
198+ ConnectTimeout : defaultHTTPConnectTimeout ,
164199 TLSTimeout : defaultTLSTimeout ,
165200 TCPKeepAlive : defaultTCPKeepAlive ,
166201 KeepAliveConnections : defaultKeepAliveConnections ,
@@ -404,7 +439,7 @@ func ConvertToRawOriginConfig(c OriginRequestConfig) config.OriginRequestConfig
404439 var keepAliveTimeout * config.CustomDuration
405440 var proxyAddress * string
406441
407- if c .ConnectTimeout != defaultConnectTimeout {
442+ if c .ConnectTimeout != defaultHTTPConnectTimeout {
408443 connectTimeout = & c .ConnectTimeout
409444 }
410445 if c .TLSTimeout != defaultTLSTimeout {
0 commit comments