mirror of https://github.com/docker/docs.git
Merge pull request #381 from vieux/closeIdleConnections
closeIdleConnections to prevent leaks with https
This commit is contained in:
commit
7b009d6d43
|
@ -180,6 +180,11 @@ func getContainerJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
|||
httpError(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// cleanup
|
||||
defer resp.Body.Close()
|
||||
defer closeIdleConnections(client)
|
||||
|
||||
data, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
httpError(w, err.Error(), http.StatusInternalServerError)
|
||||
|
|
10
api/utils.go
10
api/utils.go
|
@ -50,6 +50,13 @@ func copyHeader(dst, src http.Header) {
|
|||
}
|
||||
}
|
||||
|
||||
// prevents leak with https
|
||||
func closeIdleConnections(client *http.Client) {
|
||||
if tr, ok := client.Transport.(*http.Transport); ok {
|
||||
tr.CloseIdleConnections()
|
||||
}
|
||||
}
|
||||
|
||||
func proxyAsync(tlsConfig *tls.Config, addr string, w http.ResponseWriter, r *http.Request, callback func(*http.Response)) error {
|
||||
// Use a new client for each request
|
||||
client, scheme := newClientAndScheme(tlsConfig)
|
||||
|
@ -72,7 +79,10 @@ func proxyAsync(tlsConfig *tls.Config, addr string, w http.ResponseWriter, r *ht
|
|||
copyHeader(w.Header(), resp.Header)
|
||||
w.WriteHeader(resp.StatusCode)
|
||||
io.Copy(NewWriteFlusher(w), resp.Body)
|
||||
|
||||
// cleanup
|
||||
resp.Body.Close()
|
||||
closeIdleConnections(client)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue