Skip to content

Commit 47d4f7f

Browse files
committed
ContainerRegistry: Tolerate a missing Location header in the manifest upload response
1 parent bdb9cdb commit 47d4f7f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Sources/ContainerRegistry/Manifests.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ public extension RegistryClient {
2929
decodingErrors: [.notFound]
3030
)
3131

32-
guard let location = httpResponse.response.headerFields[.location] else {
33-
throw HTTPClientError.missingResponseHeader("Location")
34-
}
35-
return location
32+
// The distribution spec says the response MUST contain a Location header
33+
// containing a URL from which the saved manifest can be downloaded.
34+
// However some registries return URLs which cannot be fetched, and
35+
// ECR does not set this header at all.
36+
// If the header is not present, create a suitable value.
37+
// https://github.com/opencontainers/distribution-spec/blob/main/spec.md#pulling-manifests
38+
return try httpResponse.response.headerFields[.location] ?? registryURLForPath("/v2/\(repository)/manifests/\(manifest.digest)").absoluteString
3639
}
3740

3841
func getManifest(repository: String, reference: String) async throws -> ImageManifest {

0 commit comments

Comments
 (0)