Add timeouts to the probe http client

This commit is contained in:
Paul Bellamy
2016-10-12 17:20:47 +01:00
parent 7d88279758
commit 28213a00a4
2 changed files with 19 additions and 10 deletions

View File

@@ -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),

View File

@@ -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,
}
}