Support blob commit returning a 200 instead of 201

Support registries returning 204 or 200 in place of 201/202.
Ensure body is closed when request is retried.

Signed-off-by: Derek McGowan <derek@mcgstyle.net>
This commit is contained in:
Derek McGowan
2017-08-07 13:55:59 -07:00
parent e4a77fcc0a
commit 48afd44514
2 changed files with 18 additions and 2 deletions

View File

@@ -109,7 +109,10 @@ func (p dockerPusher) Push(ctx context.Context, desc ocispec.Descriptor) (conten
if err != nil {
return nil, err
}
if resp.StatusCode != http.StatusAccepted {
switch resp.StatusCode {
case http.StatusOK, http.StatusAccepted, http.StatusNoContent:
default:
// TODO: log error
return nil, errors.Errorf("unexpected response: %s", resp.Status)
}
@@ -155,7 +158,10 @@ func (p dockerPusher) Push(ctx context.Context, desc ocispec.Descriptor) (conten
pr.CloseWithError(err)
return
}
if resp.StatusCode != http.StatusCreated {
switch resp.StatusCode {
case http.StatusOK, http.StatusCreated, http.StatusNoContent:
default:
// TODO: log error
pr.CloseWithError(errors.Errorf("unexpected response: %s", resp.Status))
}
@@ -232,6 +238,14 @@ func (pw *pushWriter) Commit(size int64, expected digest.Digest, opts ...content
return errors.New("no response")
}
// 201 is specified return status, some registries return
// 200 or 204.
switch resp.StatusCode {
case http.StatusOK, http.StatusCreated, http.StatusNoContent:
default:
return errors.Errorf("unexpected status: %s", resp.Status)
}
status, err := pw.tracker.GetStatus(pw.ref)
if err != nil {
return errors.Wrap(err, "failed to get status")