mirror of
https://github.com/moby/moby.git
synced 2026-01-11 18:51:37 +00:00
api/server: allow empty body for POST /commit again
The error returned by DecodeConfig was changed inb6d58d749cand caused this to regress. Allow empty request bodies for this endpoint once again. Signed-off-by: Cory Snider <csnider@mirantis.com> (cherry picked from commit967c7bc5d3) Signed-off-by: Cory Snider <csnider@mirantis.com>
This commit is contained in:
@@ -44,7 +44,7 @@ func (s *containerRouter) postCommit(ctx context.Context, w http.ResponseWriter,
|
||||
}
|
||||
|
||||
config, _, _, err := s.decoder.DecodeConfig(r.Body)
|
||||
if err != nil && err != io.EOF { // Do not fail if body is empty.
|
||||
if err != nil && !errors.Is(err, io.EOF) { // Do not fail if body is empty.
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -484,6 +484,9 @@ func (s *containerRouter) postContainersCreate(ctx context.Context, w http.Respo
|
||||
|
||||
config, hostConfig, networkingConfig, err := s.decoder.DecodeConfig(r.Body)
|
||||
if err != nil {
|
||||
if errors.Is(err, io.EOF) {
|
||||
return errdefs.InvalidParameter(errors.New("invalid JSON: got EOF while reading request body"))
|
||||
}
|
||||
return err
|
||||
}
|
||||
version := httputils.VersionFromContext(ctx)
|
||||
|
||||
@@ -77,10 +77,7 @@ func decodeContainerConfig(src io.Reader, si *sysinfo.SysInfo) (*container.Confi
|
||||
func loadJSON(src io.Reader, out interface{}) error {
|
||||
dec := json.NewDecoder(src)
|
||||
if err := dec.Decode(&out); err != nil {
|
||||
if err == io.EOF {
|
||||
return validationError("invalid JSON: got EOF while reading request body")
|
||||
}
|
||||
return validationError("invalid JSON: " + err.Error())
|
||||
return invalidJSONError{Err: err}
|
||||
}
|
||||
if dec.More() {
|
||||
return validationError("unexpected content after JSON")
|
||||
|
||||
@@ -40,3 +40,17 @@ func (e validationError) Error() string {
|
||||
}
|
||||
|
||||
func (e validationError) InvalidParameter() {}
|
||||
|
||||
type invalidJSONError struct {
|
||||
Err error
|
||||
}
|
||||
|
||||
func (e invalidJSONError) Error() string {
|
||||
return "invalid JSON: " + e.Err.Error()
|
||||
}
|
||||
|
||||
func (e invalidJSONError) Unwrap() error {
|
||||
return e.Err
|
||||
}
|
||||
|
||||
func (e invalidJSONError) InvalidParameter() {}
|
||||
|
||||
Reference in New Issue
Block a user