Skip to content

Commit ceaf58e

Browse files
committed
fix
1 parent 0d3e995 commit ceaf58e

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed

routers/api/packages/container/container.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -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]
@@ -312,8 +323,8 @@ func InitiateUploadBlob(ctx *context.Context) {
312323
}
313324

314325
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"
317328
UploadUUID: upload.ID,
318329
Status: http.StatusAccepted,
319330
})
@@ -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
})

tests/integration/api_packages_container_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ func TestPackageContainer(t *testing.T) {
302302
resp = MakeRequest(t, req, http.StatusAccepted)
303303

304304
assert.Equal(t, uuid, resp.Header().Get("Docker-Upload-Uuid"))
305-
assert.Equal(t, contentRange, resp.Header().Get("Range"))
305+
// assert.Equal(t, contentRange, resp.Header().Get("Range"))
306306

307307
uploadURL = resp.Header().Get("Location")
308308

@@ -311,7 +311,7 @@ func TestPackageContainer(t *testing.T) {
311311
resp = MakeRequest(t, req, http.StatusNoContent)
312312

313313
assert.Equal(t, uuid, resp.Header().Get("Docker-Upload-Uuid"))
314-
assert.Equal(t, fmt.Sprintf("0-%d", len(blobContent)), resp.Header().Get("Range"))
314+
// assert.Equal(t, fmt.Sprintf("0-%d", len(blobContent)), resp.Header().Get("Range"))
315315

316316
pbu, err = packages_model.GetBlobUploadByID(db.DefaultContext, uuid)
317317
assert.NoError(t, err)
@@ -342,7 +342,7 @@ func TestPackageContainer(t *testing.T) {
342342
resp = MakeRequest(t, req, http.StatusNoContent)
343343

344344
assert.Equal(t, uuid, resp.Header().Get("Docker-Upload-Uuid"))
345-
assert.Equal(t, "0-0", resp.Header().Get("Range"))
345+
// assert.Equal(t, "0-0", resp.Header().Get("Range"))
346346

347347
req = NewRequest(t, "DELETE", setting.AppURL+uploadURL[1:]).
348348
AddTokenAuth(userToken)

0 commit comments

Comments
 (0)