@@ -48,7 +48,18 @@ type containerHeaders struct {
4848 Status int
4949 ContentDigest string
5050 UploadUUID string
51- Range string
51+
52+ // https://github.com/opencontainers/distribution-spec/blob/main/spec.md
53+ // The <range> refers to the byte range of the chunk, and MUST be inclusive on both ends.
54+ // The first chunk's range MUST begin with 0. It MUST match the following regular expression:
55+ // ^[0-9]+-[0-9]+$
56+ // Each successful chunk upload MUST have a 202 Accepted response code, and MUST have the following headers:
57+ // Location: <location>
58+ // Range: 0-<end-of-range>
59+ // Chunks MUST be uploaded in order, with the first byte of a chunk being the last chunk's <end-of-range> plus one
60+ // FIXME: It seems that the spec made a mess, it's impossible to present an empty blob, range "0-0" means one byte
61+ Range string
62+
5263 Location string
5364 ContentType string
5465 ContentLength optional.Option [int64 ]
@@ -334,7 +345,7 @@ func GetUploadBlob(ctx *context.Context) {
334345 }
335346
336347 setResponseHeaders (ctx .Resp , & containerHeaders {
337- Range : fmt .Sprintf ("0-%d" , upload .BytesReceived ),
348+ // Range: fmt.Sprintf("0-%d", upload.BytesReceived), // FIXME: not right, the "range end" should be "len-1"
338349 UploadUUID : upload .ID ,
339350 Status : http .StatusNoContent ,
340351 })
@@ -378,8 +389,8 @@ func UploadBlob(ctx *context.Context) {
378389 }
379390
380391 setResponseHeaders (ctx .Resp , & containerHeaders {
381- Location : fmt .Sprintf ("/v2/%s/%s/blobs/uploads/%s" , ctx .Package .Owner .LowerName , image , uploader .ID ),
382- Range : fmt .Sprintf ("0-%d" , uploader .Size ()- 1 ),
392+ Location : fmt .Sprintf ("/v2/%s/%s/blobs/uploads/%s" , ctx .Package .Owner .LowerName , image , uploader .ID ),
393+ // Range: fmt.Sprintf("0-%d", uploader.Size()-1), // FIXME: not right, when "uploader.Size()" is 0, it results in "0--1" which is not a valid range
383394 UploadUUID : uploader .ID ,
384395 Status : http .StatusAccepted ,
385396 })
0 commit comments