@@ -6,9 +6,34 @@ import (
6
6
"errors"
7
7
"fmt"
8
8
"net/http"
9
+ "strconv"
9
10
"time"
10
11
)
11
12
13
+ // A TunnelDuration is a Duration that has custom serialization for JSON.
14
+ // JSON in Javascript assumes that int fields are 32 bits and Duration fields
15
+ // are deserialized assuming that numbers are in nanoseconds, which in 32bit
16
+ // integers limits to just 2 seconds. This type assumes that when
17
+ // serializing/deserializing from JSON, that the number is in seconds, while it
18
+ // maintains the YAML serde assumptions.
19
+ type TunnelDuration struct {
20
+ time.Duration
21
+ }
22
+
23
+ func (s TunnelDuration ) MarshalJSON () ([]byte , error ) {
24
+ return json .Marshal (s .Duration .Seconds ())
25
+ }
26
+
27
+ func (s * TunnelDuration ) UnmarshalJSON (data []byte ) error {
28
+ seconds , err := strconv .ParseInt (string (data ), 10 , 64 )
29
+ if err != nil {
30
+ return err
31
+ }
32
+
33
+ s .Duration = time .Duration (seconds * int64 (time .Second ))
34
+ return nil
35
+ }
36
+
12
37
// ErrMissingTunnelID is for when a required tunnel ID is missing from the
13
38
// parameters.
14
39
var ErrMissingTunnelID = errors .New ("required missing tunnel ID" )
@@ -118,17 +143,17 @@ type UnvalidatedIngressRule struct {
118
143
// config.
119
144
type OriginRequestConfig struct {
120
145
// HTTP proxy timeout for establishing a new connection
121
- ConnectTimeout * time. Duration `json:"connectTimeout,omitempty"`
146
+ ConnectTimeout * TunnelDuration `json:"connectTimeout,omitempty"`
122
147
// HTTP proxy timeout for completing a TLS handshake
123
- TLSTimeout * time. Duration `json:"tlsTimeout,omitempty"`
148
+ TLSTimeout * TunnelDuration `json:"tlsTimeout,omitempty"`
124
149
// HTTP proxy TCP keepalive duration
125
- TCPKeepAlive * time. Duration `json:"tcpKeepAlive,omitempty"`
150
+ TCPKeepAlive * TunnelDuration `json:"tcpKeepAlive,omitempty"`
126
151
// HTTP proxy should disable "happy eyeballs" for IPv4/v6 fallback
127
152
NoHappyEyeballs * bool `json:"noHappyEyeballs,omitempty"`
128
153
// HTTP proxy maximum keepalive connection pool size
129
154
KeepAliveConnections * int `json:"keepAliveConnections,omitempty"`
130
155
// HTTP proxy timeout for closing an idle connection
131
- KeepAliveTimeout * time. Duration `json:"keepAliveTimeout,omitempty"`
156
+ KeepAliveTimeout * TunnelDuration `json:"keepAliveTimeout,omitempty"`
132
157
// Sets the HTTP Host header for the local webserver.
133
158
HTTPHostHeader * string `json:"httpHostHeader,omitempty"`
134
159
// Hostname on the origin server certificate.
0 commit comments