@@ -11,14 +11,16 @@ import (
1111 "github.com/cloudflare/cloudflared/tlsconfig"
1212)
1313
14- const (
15- defaultConnectTimeout = 30 * time .Second
16- defaultTLSTimeout = 10 * time .Second
17- defaultTCPKeepAlive = 30 * time .Second
18- defaultKeepAliveConnections = 100
19- defaultKeepAliveTimeout = 90 * time .Second
20- defaultProxyAddress = "127.0.0.1"
14+ var (
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 }
19+ )
2120
21+ const (
22+ defaultProxyAddress = "127.0.0.1"
23+ defaultKeepAliveConnections = 100
2224 SSHServerFlag = "ssh-server"
2325 Socks5Flag = "socks5"
2426 ProxyConnectTimeoutFlag = "proxy-connect-timeout"
@@ -68,12 +70,12 @@ func (rc *RemoteConfig) UnmarshalJSON(b []byte) error {
6870}
6971
7072func originRequestFromSingeRule (c * cli.Context ) OriginRequestConfig {
71- var connectTimeout time. Duration = defaultConnectTimeout
72- var tlsTimeout time. Duration = defaultTLSTimeout
73- var tcpKeepAlive time. Duration = defaultTCPKeepAlive
73+ var connectTimeout config. CustomDuration = defaultConnectTimeout
74+ var tlsTimeout config. CustomDuration = defaultTLSTimeout
75+ var tcpKeepAlive config. CustomDuration = defaultTCPKeepAlive
7476 var noHappyEyeballs bool
7577 var keepAliveConnections int = defaultKeepAliveConnections
76- var keepAliveTimeout time. Duration = defaultKeepAliveTimeout
78+ var keepAliveTimeout config. CustomDuration = defaultKeepAliveTimeout
7779 var httpHostHeader string
7880 var originServerName string
7981 var caPool string
@@ -84,13 +86,13 @@ func originRequestFromSingeRule(c *cli.Context) OriginRequestConfig {
8486 var proxyPort uint
8587 var proxyType string
8688 if flag := ProxyConnectTimeoutFlag ; c .IsSet (flag ) {
87- connectTimeout = c .Duration (flag )
89+ connectTimeout = config. CustomDuration { Duration : c .Duration (flag )}
8890 }
8991 if flag := ProxyTLSTimeoutFlag ; c .IsSet (flag ) {
90- tlsTimeout = c .Duration (flag )
92+ tlsTimeout = config. CustomDuration { Duration : c .Duration (flag )}
9193 }
9294 if flag := ProxyTCPKeepAliveFlag ; c .IsSet (flag ) {
93- tcpKeepAlive = c .Duration (flag )
95+ tcpKeepAlive = config. CustomDuration { Duration : c .Duration (flag )}
9496 }
9597 if flag := ProxyNoHappyEyeballsFlag ; c .IsSet (flag ) {
9698 noHappyEyeballs = c .Bool (flag )
@@ -99,7 +101,7 @@ func originRequestFromSingeRule(c *cli.Context) OriginRequestConfig {
99101 keepAliveConnections = c .Int (flag )
100102 }
101103 if flag := ProxyKeepAliveTimeoutFlag ; c .IsSet (flag ) {
102- keepAliveTimeout = c .Duration (flag )
104+ keepAliveTimeout = config. CustomDuration { Duration : c .Duration (flag )}
103105 }
104106 if flag := HTTPHostHeaderFlag ; c .IsSet (flag ) {
105107 httpHostHeader = c .String (flag )
@@ -158,13 +160,13 @@ func originRequestFromConfig(c config.OriginRequestConfig) OriginRequestConfig {
158160 ProxyAddress : defaultProxyAddress ,
159161 }
160162 if c .ConnectTimeout != nil {
161- out .ConnectTimeout = c .ConnectTimeout . Duration
163+ out .ConnectTimeout = * c .ConnectTimeout
162164 }
163165 if c .TLSTimeout != nil {
164- out .TLSTimeout = c .TLSTimeout . Duration
166+ out .TLSTimeout = * c .TLSTimeout
165167 }
166168 if c .TCPKeepAlive != nil {
167- out .TCPKeepAlive = c .TCPKeepAlive . Duration
169+ out .TCPKeepAlive = * c .TCPKeepAlive
168170 }
169171 if c .NoHappyEyeballs != nil {
170172 out .NoHappyEyeballs = * c .NoHappyEyeballs
@@ -173,7 +175,7 @@ func originRequestFromConfig(c config.OriginRequestConfig) OriginRequestConfig {
173175 out .KeepAliveConnections = * c .KeepAliveConnections
174176 }
175177 if c .KeepAliveTimeout != nil {
176- out .KeepAliveTimeout = c .KeepAliveTimeout . Duration
178+ out .KeepAliveTimeout = * c .KeepAliveTimeout
177179 }
178180 if c .HTTPHostHeader != nil {
179181 out .HTTPHostHeader = * c .HTTPHostHeader
@@ -218,52 +220,52 @@ func originRequestFromConfig(c config.OriginRequestConfig) OriginRequestConfig {
218220// Note: To specify a time.Duration in go-yaml, use e.g. "3s" or "24h".
219221type OriginRequestConfig struct {
220222 // HTTP proxy timeout for establishing a new connection
221- ConnectTimeout time. Duration `yaml:"connectTimeout"`
223+ ConnectTimeout config. CustomDuration `yaml:"connectTimeout" json :"connectTimeout"`
222224 // HTTP proxy timeout for completing a TLS handshake
223- TLSTimeout time. Duration `yaml:"tlsTimeout"`
225+ TLSTimeout config. CustomDuration `yaml:"tlsTimeout" json :"tlsTimeout"`
224226 // HTTP proxy TCP keepalive duration
225- TCPKeepAlive time. Duration `yaml:"tcpKeepAlive"`
227+ TCPKeepAlive config. CustomDuration `yaml:"tcpKeepAlive" json :"tcpKeepAlive"`
226228 // HTTP proxy should disable "happy eyeballs" for IPv4/v6 fallback
227- NoHappyEyeballs bool `yaml:"noHappyEyeballs"`
229+ NoHappyEyeballs bool `yaml:"noHappyEyeballs" json:"noHappyEyeballs" `
228230 // HTTP proxy timeout for closing an idle connection
229- KeepAliveTimeout time. Duration `yaml:"keepAliveTimeout"`
231+ KeepAliveTimeout config. CustomDuration `yaml:"keepAliveTimeout" json :"keepAliveTimeout"`
230232 // HTTP proxy maximum keepalive connection pool size
231- KeepAliveConnections int `yaml:"keepAliveConnections"`
233+ KeepAliveConnections int `yaml:"keepAliveConnections" json:"keepAliveConnections" `
232234 // Sets the HTTP Host header for the local webserver.
233- HTTPHostHeader string `yaml:"httpHostHeader"`
235+ HTTPHostHeader string `yaml:"httpHostHeader" json:"httpHostHeader" `
234236 // Hostname on the origin server certificate.
235- OriginServerName string `yaml:"originServerName"`
237+ OriginServerName string `yaml:"originServerName" json:"originServerName" `
236238 // Path to the CA for the certificate of your origin.
237239 // This option should be used only if your certificate is not signed by Cloudflare.
238- CAPool string `yaml:"caPool"`
240+ CAPool string `yaml:"caPool" json:"caPool" `
239241 // Disables TLS verification of the certificate presented by your origin.
240242 // Will allow any certificate from the origin to be accepted.
241243 // Note: The connection from your machine to Cloudflare's Edge is still encrypted.
242- NoTLSVerify bool `yaml:"noTLSVerify"`
244+ NoTLSVerify bool `yaml:"noTLSVerify" json:"noTLSVerify" `
243245 // Disables chunked transfer encoding.
244246 // Useful if you are running a WSGI server.
245- DisableChunkedEncoding bool `yaml:"disableChunkedEncoding"`
247+ DisableChunkedEncoding bool `yaml:"disableChunkedEncoding" json:"disableChunkedEncoding" `
246248 // Runs as jump host
247- BastionMode bool `yaml:"bastionMode"`
249+ BastionMode bool `yaml:"bastionMode" json:"bastionMode" `
248250 // Listen address for the proxy.
249- ProxyAddress string `yaml:"proxyAddress"`
251+ ProxyAddress string `yaml:"proxyAddress" json:"proxyAddress" `
250252 // Listen port for the proxy.
251- ProxyPort uint `yaml:"proxyPort"`
253+ ProxyPort uint `yaml:"proxyPort" json:"proxyPort" `
252254 // What sort of proxy should be started
253- ProxyType string `yaml:"proxyType"`
255+ ProxyType string `yaml:"proxyType" json:"proxyType" `
254256 // IP rules for the proxy service
255- IPRules []ipaccess.Rule `yaml:"ipRules"`
257+ IPRules []ipaccess.Rule `yaml:"ipRules" json:"ipRules" `
256258}
257259
258260func (defaults * OriginRequestConfig ) setConnectTimeout (overrides config.OriginRequestConfig ) {
259261 if val := overrides .ConnectTimeout ; val != nil {
260- defaults .ConnectTimeout = val . Duration
262+ defaults .ConnectTimeout = * val
261263 }
262264}
263265
264266func (defaults * OriginRequestConfig ) setTLSTimeout (overrides config.OriginRequestConfig ) {
265267 if val := overrides .TLSTimeout ; val != nil {
266- defaults .TLSTimeout = val . Duration
268+ defaults .TLSTimeout = * val
267269 }
268270}
269271
@@ -281,13 +283,13 @@ func (defaults *OriginRequestConfig) setKeepAliveConnections(overrides config.Or
281283
282284func (defaults * OriginRequestConfig ) setKeepAliveTimeout (overrides config.OriginRequestConfig ) {
283285 if val := overrides .KeepAliveTimeout ; val != nil {
284- defaults .KeepAliveTimeout = val . Duration
286+ defaults .KeepAliveTimeout = * val
285287 }
286288}
287289
288290func (defaults * OriginRequestConfig ) setTCPKeepAlive (overrides config.OriginRequestConfig ) {
289291 if val := overrides .TCPKeepAlive ; val != nil {
290- defaults .TCPKeepAlive = val . Duration
292+ defaults .TCPKeepAlive = * val
291293 }
292294}
293295
0 commit comments