Skip to content
This repository has been archived by the owner on Apr 20, 2021. It is now read-only.

Commit

Permalink
Add timeouts to the probe http client
Browse files Browse the repository at this point in the history
  • Loading branch information
paulbellamy committed Oct 12, 2016
1 parent 7d88279 commit 28213a0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
3 changes: 2 additions & 1 deletion probe/appclient/app_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func NewAppClient(pc ProbeConfig, hostname string, target url.URL, control xfer.
Timeout: httpClientTimeout,
},
wsDialer: websocket.Dialer{
TLSClientConfig: httpTransport.TLSClientConfig,
TLSClientConfig: httpTransport.TLSClientConfig,
HandshakeTimeout: httpClientTimeout,
},
conns: map[string]xfer.Websocket{},
readers: make(chan io.Reader, 2),
Expand Down
26 changes: 17 additions & 9 deletions probe/appclient/probe_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,24 @@ func (pc ProbeConfig) authorizedRequest(method string, urlStr string, body io.Re
}

func (pc ProbeConfig) getHTTPTransport(hostname string) (*http.Transport, error) {
var tlsConfig *tls.Config
if pc.Insecure {
return &http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
}, nil
}

return &http.Transport{
TLSClientConfig: &tls.Config{
tlsConfig = &tls.Config{InsecureSkipVerify: true}
} else {
tlsConfig = &tls.Config{
RootCAs: certPool,
ServerName: hostname,
},
}, nil
}
}
return &http.Transport{
TLSClientConfig: tlsConfig,

DialContext: (&net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}).DialContext,
IdleConnTimeout: http.DefaultTransport.IdleConnTimeout,
TLSHandshakeTimeout: http.DefaultTransport.TLSHandshakeTimeout,
ExpectContinueTimeout: http.DefaultTransport.ExpectContinueTimeout,
}
}

0 comments on commit 28213a0

Please sign in to comment.