Skip to content

Commit

Permalink
fix(routes): get blob upload session should include 'bytes=' in Range…
Browse files Browse the repository at this point in the history
… header

needed to change because of OCI distribution spec change in test:
https://github.com/opencontainers/distribution-spec/blob/main/conformance/02_push_test.go#L223

Signed-off-by: Petu Eusebiu <peusebiu@cisco.com>
  • Loading branch information
eusebiu-constantin-petu-dbk authored and rchincha committed Apr 14, 2023
1 parent e63faa8 commit ea9b30f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 13 deletions.
14 changes: 7 additions & 7 deletions pkg/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ func (rh *RouteHandler) DeleteBlob(response http.ResponseWriter, request *http.R
// @Param name path string true "repository name"
// @Success 202 {string} string "accepted"
// @Header 202 {string} Location "/v2/{name}/blobs/uploads/{session_id}"
// @Header 202 {string} Range "0-0"
// @Header 202 {string} Range "bytes=0-0"
// @Failure 404 {string} string "not found"
// @Failure 500 {string} string "internal server error"
// @Router /v2/{name}/blobs/uploads [post].
Expand Down Expand Up @@ -1044,7 +1044,7 @@ func (rh *RouteHandler) CreateBlobUpload(response http.ResponseWriter, request *
}

response.Header().Set("Location", getBlobUploadSessionLocation(request.URL, upload))
response.Header().Set("Range", "0-0")
response.Header().Set("Range", "bytes=0-0")
response.WriteHeader(http.StatusAccepted)

return
Expand Down Expand Up @@ -1130,7 +1130,7 @@ func (rh *RouteHandler) CreateBlobUpload(response http.ResponseWriter, request *
}

response.Header().Set("Location", getBlobUploadSessionLocation(request.URL, upload))
response.Header().Set("Range", "0-0")
response.Header().Set("Range", "bytes=0-0")
response.WriteHeader(http.StatusAccepted)
}

Expand All @@ -1143,7 +1143,7 @@ func (rh *RouteHandler) CreateBlobUpload(response http.ResponseWriter, request *
// @Param session_id path string true "upload session_id"
// @Success 204 {string} string "no content"
// @Header 202 {string} Location "/v2/{name}/blobs/uploads/{session_id}"
// @Header 202 {string} Range "0-128"
// @Header 202 {string} Range "bytes=0-128"
// @Failure 404 {string} string "not found"
// @Failure 500 {string} string "internal server error"
// @Router /v2/{name}/blobs/uploads/{session_id} [get].
Expand Down Expand Up @@ -1189,7 +1189,7 @@ func (rh *RouteHandler) GetBlobUpload(response http.ResponseWriter, request *htt
}

response.Header().Set("Location", getBlobUploadSessionLocation(request.URL, sessionID))
response.Header().Set("Range", fmt.Sprintf("0-%d", size-1))
response.Header().Set("Range", fmt.Sprintf("bytes=0-%d", size-1))
response.WriteHeader(http.StatusNoContent)
}

Expand All @@ -1202,7 +1202,7 @@ func (rh *RouteHandler) GetBlobUpload(response http.ResponseWriter, request *htt
// @Param session_id path string true "upload session_id"
// @Success 202 {string} string "accepted"
// @Header 202 {string} Location "/v2/{name}/blobs/uploads/{session_id}"
// @Header 202 {string} Range "0-128"
// @Header 202 {string} Range "bytes=0-128"
// @Header 200 {object} api.BlobUploadUUID
// @Failure 400 {string} string "bad request"
// @Failure 404 {string} string "not found"
Expand Down Expand Up @@ -1281,7 +1281,7 @@ func (rh *RouteHandler) PatchBlobUpload(response http.ResponseWriter, request *h
}

response.Header().Set("Location", getBlobUploadSessionLocation(request.URL, sessionID))
response.Header().Set("Range", fmt.Sprintf("0-%d", clen-1))
response.Header().Set("Range", fmt.Sprintf("bytes=0-%d", clen-1))
response.Header().Set("Content-Length", "0")
response.Header().Set(constants.BlobUploadUUID, sessionID)
response.WriteHeader(http.StatusAccepted)
Expand Down
4 changes: 2 additions & 2 deletions pkg/compliance/v1_0_0/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
So(resp.StatusCode(), ShouldEqual, http.StatusNoContent)
r := resp.Header().Get("Range")
So(r, ShouldNotBeEmpty)
So(r, ShouldEqual, contentRange)
So(r, ShouldEqual, fmt.Sprintf("bytes=%s", contentRange))

// write same chunk should fail
contentRange = fmt.Sprintf("%d-%d", 0, len(chunk1)-1)
Expand Down Expand Up @@ -356,7 +356,7 @@ func CheckWorkflows(t *testing.T, config *compliance.Config) {
So(resp.StatusCode(), ShouldEqual, http.StatusNoContent)
r := resp.Header().Get("Range")
So(r, ShouldNotBeEmpty)
So(r, ShouldEqual, contentRange)
So(r, ShouldEqual, fmt.Sprintf("bytes=%s", contentRange))

// write same chunk should fail
contentRange = fmt.Sprintf("%d-%d", 0, len(chunk1)-1)
Expand Down
2 changes: 1 addition & 1 deletion swagger/docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ var doc = `{
},
"Range": {
"type": "string",
"description": "0-0"
"description": "bytes=0-0"
}
}
},
Expand Down
6 changes: 3 additions & 3 deletions swagger/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@
},
"Range": {
"type": "string",
"description": "0-0"
"description": "bytes=0-0"
}
}
},
Expand Down Expand Up @@ -371,7 +371,7 @@
},
"Range": {
"type": "string",
"description": "0-128"
"description": "bytes=0-128"
}
}
},
Expand Down Expand Up @@ -793,4 +793,4 @@
}
}
}
}
}

0 comments on commit ea9b30f

Please sign in to comment.