diff --git a/app/handler/blob.go b/app/handler/blob.go index f0b0a12..e196b1a 100644 --- a/app/handler/blob.go +++ b/app/handler/blob.go @@ -60,6 +60,15 @@ func (hand *Handler) BlobExists(rctx *router.Context) { func (hand *Handler) PostUpload(rctx *router.Context) { name, _ := rctx.GetSubpath("name") + hand.DumpHeaders("PostUploads", rctx) + + authorization := rctx.GetHeader("Authorization") + if authorization == "" { + rctx.SetHeader("WWW-Authenticate", `Basic realm="mstore"`) + rctx.SetStatus(http.StatusUnauthorized) + return + } + digest := rctx.GetQuery("digest") mount := rctx.GetQuery("mount") from := rctx.GetQuery("from") @@ -150,6 +159,7 @@ func (hand *Handler) PutUpload(rctx *router.Context) { reference, _ := rctx.GetSubpath("reference") digest := rctx.GetQuery("digest") + reader := rctx.Request.Body params := &operator.PutUploadParams{ ContentLength: contentLength, @@ -158,6 +168,7 @@ func (hand *Handler) PutUpload(rctx *router.Context) { Name: name, Reference: reference, Digest: digest, + Reader: reader, } // Rigth checking operatorID, _ := rctx.GetString(userTag) diff --git a/app/operator/blob.go b/app/operator/blob.go index f0f7946..1db3cb3 100644 --- a/app/operator/blob.go +++ b/app/operator/blob.go @@ -217,9 +217,19 @@ func (oper *Operator) PutUpload(ctx context.Context, operatorID string, params * } if contentLength != 0 { - // TODO - err = fmt.Errorf("Unexpected Content-Length header: %s", params.ContentLength) - return res, http.StatusInternalServerError, err + recsize, _, err := oper.store.WriteUpload(params.Reference, params.Reader) + if err != nil { + return res, http.StatusInternalServerError, err + } + if contentLength != 0 && recsize != contentLength { + oper.store.RemoveUpload(params.Reference) + err = fmt.Errorf("Mismatch upload recorded size and content length") + return res, http.StatusInternalServerError, err + } + if err != nil { + return res, http.StatusInternalServerError, err + } + res.Location = fmt.Sprintf("/v2/%s/blobs/%s", params.Name, params.Digest) } err = oper.store.LinkUpload(params.Reference, params.Digest)