@@ -313,13 +313,12 @@ func InitiateUploadBlob(ctx *context.Context) {
313
313
314
314
setResponseHeaders (ctx .Resp , & containerHeaders {
315
315
Location : fmt .Sprintf ("/v2/%s/%s/blobs/uploads/%s" , ctx .Package .Owner .LowerName , image , upload .ID ),
316
- Range : "0-0" ,
317
316
UploadUUID : upload .ID ,
318
317
Status : http .StatusAccepted ,
319
318
})
320
319
}
321
320
322
- // https://docs.docker. com/registry/ spec/api/#get- blob-upload
321
+ // https://github. com/opencontainers/distribution- spec/blob/main/spec.md#pushing-a- blob-in-chunks
323
322
func GetUploadBlob (ctx * context.Context ) {
324
323
uuid := ctx .PathParam ("uuid" )
325
324
@@ -333,13 +332,18 @@ func GetUploadBlob(ctx *context.Context) {
333
332
return
334
333
}
335
334
336
- setResponseHeaders ( ctx . Resp , & containerHeaders {
337
- Range : fmt . Sprintf ( "0-%d" , upload . BytesReceived ),
335
+ // FIXME: undefined behavior when the uploaded content is empty: https://github.com/opencontainers/distribution-spec/issues/578
336
+ respHeaders := & containerHeaders {
338
337
UploadUUID : upload .ID ,
339
338
Status : http .StatusNoContent ,
340
- })
339
+ }
340
+ if upload .BytesReceived > 0 {
341
+ respHeaders .Range = fmt .Sprintf ("0-%d" , upload .BytesReceived - 1 )
342
+ }
343
+ setResponseHeaders (ctx .Resp , respHeaders )
341
344
}
342
345
346
+ // https://github.com/opencontainers/distribution-spec/blob/main/spec.md#single-post
343
347
// https://github.com/opencontainers/distribution-spec/blob/main/spec.md#pushing-a-blob-in-chunks
344
348
func UploadBlob (ctx * context.Context ) {
345
349
image := ctx .PathParam ("image" )
@@ -377,12 +381,15 @@ func UploadBlob(ctx *context.Context) {
377
381
return
378
382
}
379
383
380
- setResponseHeaders ( ctx . Resp , & containerHeaders {
384
+ respHeaders := & containerHeaders {
381
385
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 ),
383
386
UploadUUID : uploader .ID ,
384
387
Status : http .StatusAccepted ,
385
- })
388
+ }
389
+ if contentRange != "" {
390
+ respHeaders .Range = fmt .Sprintf ("0-%d" , uploader .Size ()- 1 )
391
+ }
392
+ setResponseHeaders (ctx .Resp , respHeaders )
386
393
}
387
394
388
395
// https://github.com/opencontainers/distribution-spec/blob/main/spec.md#pushing-a-blob-in-chunks
0 commit comments