Skip to content

Commit

Permalink
Do not include Content-Range for monolithic uploads (#179)
Browse files Browse the repository at this point in the history
* Do not include Content-Range for monolithic uploads

Some registries still assumes it's a chunked upload and verifies the "chunk" size which is too big.

* Update Sources/tart/OCI/Registry.swift

Co-authored-by: Nikolay Edigaryev <[email protected]>

Co-authored-by: Nikolay Edigaryev <[email protected]>
  • Loading branch information
fkorotkov and edigaryev authored Aug 12, 2022
1 parent cc8201d commit a80954c
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions Sources/tart/OCI/Registry.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,27 @@ class Registry {
var uploadLocation = try uploadLocationFromResponse(postResponse)

let digest = Digest.hash(fromData)

if chunkSizeMb == 0 {
// monolithic upload
let response = try await rawRequest(
.PUT,
uploadLocation,
headers: [
"Content-Type": "application/octet-stream",
],
parameters: ["digest": digest],
body: fromData
)
if response.status != .created {
let body = try await response.body.readTextResponse()
throw RegistryError.UnexpectedHTTPStatusCode(when: "pushing blob (PUT) to \(uploadLocation)",
code: response.status.code, details: body ?? "")
}
return digest
}

// chunked upload
var uploadedBytes = 0
let chunks = fromData.chunks(ofCount: chunkSizeMb == 0 ? fromData.count : chunkSizeMb * 1_000_000)
for (index, chunk) in chunks.enumerated() {
Expand Down

0 comments on commit a80954c

Please sign in to comment.