Skip to content

Commit

Permalink
Add TCP idle timeout (sideshow#24)
Browse files Browse the repository at this point in the history
  • Loading branch information
closer committed Feb 22, 2018
1 parent df275e5 commit 54777a6
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ var (
// TCPKeepAlive specifies the keep-alive period for an active network
// connection. If zero, keep-alives are not enabled.
TCPKeepAlive = 60 * time.Second
// TCPIdleTimeout specifies the maximum amount of time an idle
// (keep-alive) connection will remain idle before closing
// itself.
// If zero, are no limit.
TCPIdleTimeout = 0 * time.Second
)

// DialTLS is the default dial function for creating TLS connections for
Expand Down Expand Up @@ -80,6 +85,9 @@ func NewClient(certificate tls.Certificate) *Client {
tlsConfig.BuildNameToCertificate()
}
transport := &http2.Transport{
http2.t1: &http.Transport{
IdleConnTimeout: TCPIdleTimeout,
},
TLSClientConfig: tlsConfig,
DialTLS: DialTLS,
}
Expand All @@ -103,7 +111,10 @@ func NewClient(certificate tls.Certificate) *Client {
// connection and disconnection as a denial-of-service attack.
func NewTokenClient(token *token.Token) *Client {
transport := &http2.Transport{
DialTLS: DialTLS,
http2.t1: &http.Transport{
IdleConnTimeout: TCPIdleTimeout,
},
DialTLS: DialTLS,
}
return &Client{
Token: token,
Expand Down

0 comments on commit 54777a6

Please sign in to comment.