mirror of https://github.com/docker/docs.git
closeIdleConnections to prevent leaks with https
Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
parent
36440405f4
commit
7401789862
|
|
@ -180,6 +180,11 @@ func getContainerJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
||||||
httpError(w, err.Error(), http.StatusInternalServerError)
|
httpError(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// cleanup
|
||||||
|
defer resp.Body.Close()
|
||||||
|
defer closeIdleConnections(client)
|
||||||
|
|
||||||
data, err := ioutil.ReadAll(resp.Body)
|
data, err := ioutil.ReadAll(resp.Body)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httpError(w, err.Error(), http.StatusInternalServerError)
|
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 {
|
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
|
// Use a new client for each request
|
||||||
client, scheme := newClientAndScheme(tlsConfig)
|
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)
|
copyHeader(w.Header(), resp.Header)
|
||||||
w.WriteHeader(resp.StatusCode)
|
w.WriteHeader(resp.StatusCode)
|
||||||
io.Copy(NewWriteFlusher(w), resp.Body)
|
io.Copy(NewWriteFlusher(w), resp.Body)
|
||||||
|
|
||||||
|
// cleanup
|
||||||
resp.Body.Close()
|
resp.Body.Close()
|
||||||
|
closeIdleConnections(client)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue