mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
client: remove redundant closing and draining of response
For methods using the decodeWithRaw utility, we were handling closing of the body twice. The ensureReaderClosed utility also drains the response to let the transport reuse the connnection. Let's use that utility in decodeWithRaw as well. Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
@@ -25,7 +25,6 @@ func (cli *Client) ConfigInspect(ctx context.Context, id string, options ConfigI
|
||||
return ConfigInspectResult{}, err
|
||||
}
|
||||
resp, err := cli.get(ctx, "/configs/"+id, nil, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
if err != nil {
|
||||
return ConfigInspectResult{}, err
|
||||
}
|
||||
|
||||
@@ -29,7 +29,6 @@ func (cli *Client) NetworkInspect(ctx context.Context, networkID string, options
|
||||
}
|
||||
|
||||
resp, err := cli.get(ctx, "/networks/"+networkID, query, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
if err != nil {
|
||||
return NetworkInspectResult{}, err
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ func (cli *Client) PluginInspect(ctx context.Context, name string, options Plugi
|
||||
return PluginInspectResult{}, err
|
||||
}
|
||||
resp, err := cli.get(ctx, "/plugins/"+name+"/json", nil, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
if err != nil {
|
||||
return PluginInspectResult{}, err
|
||||
}
|
||||
|
||||
@@ -25,7 +25,6 @@ func (cli *Client) SecretInspect(ctx context.Context, id string, options SecretI
|
||||
return SecretInspectResult{}, err
|
||||
}
|
||||
resp, err := cli.get(ctx, "/secrets/"+id, nil, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
if err != nil {
|
||||
return SecretInspectResult{}, err
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ func (cli *Client) ServiceInspect(ctx context.Context, serviceID string, options
|
||||
query := url.Values{}
|
||||
query.Set("insertDefaults", fmt.Sprintf("%v", options.InsertDefaults))
|
||||
resp, err := cli.get(ctx, "/services/"+serviceID, query, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
if err != nil {
|
||||
return ServiceInspectResult{}, err
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ func (cli *Client) TaskInspect(ctx context.Context, taskID string, options TaskI
|
||||
}
|
||||
|
||||
resp, err := cli.get(ctx, "/tasks/"+taskID, nil, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
if err != nil {
|
||||
return TaskInspectResult{}, err
|
||||
}
|
||||
|
||||
@@ -74,7 +74,7 @@ func decodeWithRaw[T any](resp *http.Response, out *T) (raw json.RawMessage, _ e
|
||||
if resp == nil || resp.Body == nil {
|
||||
return nil, errors.New("empty response")
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
defer ensureReaderClosed(resp)
|
||||
|
||||
var buf bytes.Buffer
|
||||
tr := io.TeeReader(resp.Body, &buf)
|
||||
|
||||
@@ -26,7 +26,6 @@ func (cli *Client) VolumeInspect(ctx context.Context, volumeID string, options V
|
||||
}
|
||||
|
||||
resp, err := cli.get(ctx, "/volumes/"+volumeID, nil, nil)
|
||||
defer ensureReaderClosed(resp)
|
||||
if err != nil {
|
||||
return VolumeInspectResult{}, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user