From 2ff5f5bf8053cf49201320d6714d246889ce2dfc Mon Sep 17 00:00:00 2001 From: Wayne Warren Date: Thu, 30 Jul 2020 02:20:38 +0000 Subject: [PATCH] OCI: POST request with digest and blob should yield 201 --- registry/handlers/blobupload.go | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/registry/handlers/blobupload.go b/registry/handlers/blobupload.go index d0351e3e4..e8e35ed41 100644 --- a/registry/handlers/blobupload.go +++ b/registry/handlers/blobupload.go @@ -29,9 +29,9 @@ func blobUploadDispatcher(ctx *Context, r *http.Request) http.Handler { } if !ctx.readOnly { - handler["POST"] = http.HandlerFunc(buh.StartBlobUpload) + handler["POST"] = http.HandlerFunc(buh.PostBlobData) handler["PATCH"] = http.HandlerFunc(buh.PatchBlobData) - handler["PUT"] = http.HandlerFunc(buh.PutBlobUploadComplete) + handler["PUT"] = http.HandlerFunc(buh.BlobUploadComplete) handler["DELETE"] = http.HandlerFunc(buh.CancelBlobUpload) } @@ -97,6 +97,7 @@ func (buh *blobUploadHandler) StartBlobUpload(w http.ResponseWriter, r *http.Req } w.Header().Set("Docker-Upload-UUID", buh.Upload.ID()) + w.WriteHeader(http.StatusAccepted) } @@ -148,15 +149,24 @@ func (buh *blobUploadHandler) PatchBlobData(w http.ResponseWriter, r *http.Reque w.WriteHeader(http.StatusAccepted) } -// PutBlobUploadComplete takes the final request of a blob upload. The -// request may include all the blob data or no blob data. Any data -// provided is received and verified. If successful, the blob is linked -// into the blob store and 201 Created is returned with the canonical -// url of the blob. -func (buh *blobUploadHandler) PutBlobUploadComplete(w http.ResponseWriter, r *http.Request) { +// PostBlobData writes upload data to a blob. +func (buh *blobUploadHandler) PostBlobData(w http.ResponseWriter, r *http.Request) { + if r.FormValue("digest") != "" && r.ContentLength > 0 { + buh.BlobUploadComplete(w, r) + } else { + buh.StartBlobUpload(w, r) + } +} + +// BlobUploadComplete takes the final request of a blob upload. The request may +// include all the blob data or no blob data. Any data provided is received and +// verified. If successful, the blob is linked into the blob store and 201 +// Created is returned with the canonical url of the blob. +func (buh *blobUploadHandler) BlobUploadComplete(w http.ResponseWriter, r *http.Request) { + var err error if buh.Upload == nil { - buh.Errors = append(buh.Errors, v2.ErrorCodeBlobUploadUnknown) - return + blobs := buh.Repository.Blobs(buh) + buh.Upload, err = blobs.Create(buh) } dgstStr := r.FormValue("digest") // TODO(stevvooe): Support multiple digest parameters!