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:
		| @@ -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") | ||||
|   | ||||
| @@ -313,9 +313,11 @@ func (r *dockerBase) doRequestWithRetries(ctx context.Context, req *http.Request | ||||
| 	responses = append(responses, resp) | ||||
| 	req, err = r.retryRequest(ctx, req, responses) | ||||
| 	if err != nil { | ||||
| 		resp.Body.Close() | ||||
| 		return nil, err | ||||
| 	} | ||||
| 	if req != nil { | ||||
| 		resp.Body.Close() | ||||
| 		return r.doRequestWithRetries(ctx, req, responses) | ||||
| 	} | ||||
| 	return resp, err | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Derek McGowan
					Derek McGowan