OCI: POST request with digest and blob should yield 201

This commit is contained in:
Wayne Warren 2020-07-30 02:20:38 +00:00
parent f8c65fc7c5
commit 2ff5f5bf80

View File

@ -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!