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:
parent
e4a77fcc0a
commit
48afd44514
@ -109,7 +109,10 @@ func (p dockerPusher) Push(ctx context.Context, desc ocispec.Descriptor) (conten
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if resp.StatusCode != http.StatusAccepted {
|
|
||||||
|
switch resp.StatusCode {
|
||||||
|
case http.StatusOK, http.StatusAccepted, http.StatusNoContent:
|
||||||
|
default:
|
||||||
// TODO: log error
|
// TODO: log error
|
||||||
return nil, errors.Errorf("unexpected response: %s", resp.Status)
|
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)
|
pr.CloseWithError(err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if resp.StatusCode != http.StatusCreated {
|
|
||||||
|
switch resp.StatusCode {
|
||||||
|
case http.StatusOK, http.StatusCreated, http.StatusNoContent:
|
||||||
|
default:
|
||||||
// TODO: log error
|
// TODO: log error
|
||||||
pr.CloseWithError(errors.Errorf("unexpected response: %s", resp.Status))
|
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")
|
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)
|
status, err := pw.tracker.GetStatus(pw.ref)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to get status")
|
return errors.Wrap(err, "failed to get status")
|
||||||
|
@ -313,9 +313,11 @@ func (r *dockerBase) doRequestWithRetries(ctx context.Context, req *http.Request
|
|||||||
responses = append(responses, resp)
|
responses = append(responses, resp)
|
||||||
req, err = r.retryRequest(ctx, req, responses)
|
req, err = r.retryRequest(ctx, req, responses)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
resp.Body.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if req != nil {
|
if req != nil {
|
||||||
|
resp.Body.Close()
|
||||||
return r.doRequestWithRetries(ctx, req, responses)
|
return r.doRequestWithRetries(ctx, req, responses)
|
||||||
}
|
}
|
||||||
return resp, err
|
return resp, err
|
||||||
|
Loading…
Reference in New Issue
Block a user