Skip to content

Commit 846c833

Browse files
committed
cli/command/image: remove uses of JSON field
The JSON field was added in [moby@9fd2c0f], to address [moby#19177], which reported an incompatibility with Classic (V1) Swarm, which produced a non- standard response; > Make docker load to output json when the response content type is json > Swarm hijacks the response from docker load and returns JSON rather > than plain text like the Engine does. This makes the API library to return > information to figure that out. A later change in [moby@96d7db6] added additional logic to make sure the correct content-type was returned, depending on whether the `quiet` option was set (which produced a non-JSON response). This caused inconsistency in the API response, and [moby@2f27632] changed the endpoint to always produce JSON (only skipping the "progress" output if `quiet` was set). This means that the "load" endpoint ([`imageRouter.postImagesLoad`]) now unconditionally returns JSON, making the `JSON` field fully redundant. This patch removes the use of the JSON field, as it's redundant, and the way it handles the content-type is incorrect because it would not handle correct, but different formatted response-headers (`application/json; charset=utf-8`), which could result in malformed output on the client. [moby@9fd2c0f]: moby/moby@9fd2c0f [moby#19177]: moby/moby#19177 [moby@96d7db6]: moby/moby@96d7db6 [moby@2f27632]: moby/moby@2f27632 [`imageRouter.postImagesLoad`]: https://github.com/moby/moby/blob/7b9d2ef6e5518a3d3f3cc418459f8df786cfbbd1/api/server/router/image/image_routes.go#L248-L255 Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent dafbfc2 commit 846c833

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

cli/command/image/load.go

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func runLoad(ctx context.Context, dockerCli command.Cli, opts loadOptions) error
7070
if err != nil {
7171
return err
7272
}
73-
defer file.Close()
73+
defer func() { _ = file.Close() }()
7474
input = file
7575
}
7676

@@ -95,12 +95,7 @@ func runLoad(ctx context.Context, dockerCli command.Cli, opts loadOptions) error
9595
if err != nil {
9696
return err
9797
}
98-
defer res.Close()
98+
defer func() { _ = res.Close() }()
9999

100-
if res.JSON {
101-
return jsonstream.Display(ctx, res, dockerCli.Out())
102-
}
103-
104-
_, err = io.Copy(dockerCli.Out(), res)
105-
return err
100+
return jsonstream.Display(ctx, res, dockerCli.Out())
106101
}

0 commit comments

Comments
 (0)