@@ -48,7 +48,18 @@ type containerHeaders struct {
48
48
Status int
49
49
ContentDigest string
50
50
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
+
52
63
Location string
53
64
ContentType string
54
65
ContentLength optional.Option [int64 ]
@@ -312,8 +323,8 @@ func InitiateUploadBlob(ctx *context.Context) {
312
323
}
313
324
314
325
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" ,
326
+ Location : fmt .Sprintf ("/v2/%s/%s/blobs/uploads/%s" , ctx .Package .Owner .LowerName , image , upload .ID ),
327
+ // Range: "0-0", // FIXME: not right, the "range end" should be "len-1"
317
328
UploadUUID : upload .ID ,
318
329
Status : http .StatusAccepted ,
319
330
})
@@ -334,7 +345,7 @@ func GetUploadBlob(ctx *context.Context) {
334
345
}
335
346
336
347
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"
338
349
UploadUUID : upload .ID ,
339
350
Status : http .StatusNoContent ,
340
351
})
@@ -378,8 +389,8 @@ func UploadBlob(ctx *context.Context) {
378
389
}
379
390
380
391
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
383
394
UploadUUID : uploader .ID ,
384
395
Status : http .StatusAccepted ,
385
396
})
0 commit comments