ensures that transport.Client is closed while using cli.NewClient with *http.Client = nil.

Signed-off-by: qudongfang <qudongfang@gmail.com>
Upstream-commit: 9403a5b63e
Component: cli
This commit is contained in:
qudongfang
2016-09-08 09:57:54 +08:00
parent 412bbe39eb
commit 700f218052
2 changed files with 18 additions and 0 deletions

View File

@ -108,6 +108,19 @@ func NewClient(host string, version string, client *http.Client, httpHeaders map
}, nil
}
// Close ensures that transport.Client is closed
// especially needed while using NewClient with *http.Client = nil
// for example
// client.NewClient("unix:///var/run/docker.sock", nil, "v1.18", map[string]string{"User-Agent": "engine-api-cli-1.0"})
func (cli *Client) Close() error {
if t, ok := cli.client.Transport.(*http.Transport); ok {
t.CloseIdleConnections()
}
return nil
}
// getAPIPath returns the versioned request path to call the api.
// It appends the query parameters to the path if they are not empty.
func (cli *Client) getAPIPath(p string, query url.Values) string {