@@ -48,7 +48,20 @@ 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+ //
62+ // Fortunately, spec v1.0 doesn't require the "Range" header: https://specs.opencontainers.org/distribution-spec/?v=v1.0.0#post-then-put
63+ Range string
64+
5265 Location string
5366 ContentType string
5467 ContentLength optional.Option [int64 ]
@@ -312,8 +325,8 @@ func InitiateUploadBlob(ctx *context.Context) {
312325 }
313326
314327 setResponseHeaders (ctx .Resp , & containerHeaders {
315- Location : fmt .Sprintf ("/v2/%s/%s/blobs/uploads/%s" , ctx .Package .Owner .LowerName , image , upload .ID ),
316- Range : "0-0" ,
328+ Location : fmt .Sprintf ("/v2/%s/%s/blobs/uploads/%s" , ctx .Package .Owner .LowerName , image , upload .ID ),
329+ // Range: "0-0", // FIXME: not right, the "range end" should be "len-1"
317330 UploadUUID : upload .ID ,
318331 Status : http .StatusAccepted ,
319332 })
@@ -334,7 +347,7 @@ func GetUploadBlob(ctx *context.Context) {
334347 }
335348
336349 setResponseHeaders (ctx .Resp , & containerHeaders {
337- Range : fmt .Sprintf ("0-%d" , upload .BytesReceived ),
350+ // Range: fmt.Sprintf("0-%d", upload.BytesReceived), // FIXME: not right, the "range end" should be "len-1"
338351 UploadUUID : upload .ID ,
339352 Status : http .StatusNoContent ,
340353 })
@@ -378,8 +391,8 @@ func UploadBlob(ctx *context.Context) {
378391 }
379392
380393 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 ),
394+ Location : fmt .Sprintf ("/v2/%s/%s/blobs/uploads/%s" , ctx .Package .Owner .LowerName , image , uploader .ID ),
395+ // 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
383396 UploadUUID : uploader .ID ,
384397 Status : http .StatusAccepted ,
385398 })
0 commit comments