Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix media types in Accept header for Docker Registry #3119

Merged
merged 2 commits into from
Feb 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions docker/lib/dependabot/docker/update_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,23 @@ class Registry
private

# By default the Docker Registry client sets the Accept header to
# `application/vnd.docker.distribution.manifest.v2+json`
# This results in the digest of a specific platform to be returned, we
# want to override this header so we can fetch the generic digest
# associated with the given repo/tag.
# `application/vnd.docker.distribution.manifest.v2+json`. This is fine for
# most images, but for multi-architecture images, it fetches the digest of a
# specific architecture instead of the digest for the multi-architecture
# image. We override the header to tell the Docker API to vary its behavior
# depending on whether the image is a uses a traditional (non-list) manifest
# or a manifest list. If the image uses a traditional manifest, the API will
# return the manifest digest. If the image uses a manifest list, the API
# will return the manifest list digest.
def headers(payload: nil, bearer_token: nil)
headers = {}
headers["Authorization"] = "Bearer #{bearer_token}" unless bearer_token.nil?
if payload.nil?
headers["Accept"] =
"application/vnd.docker.distribution.manifest.list.v2+json, application/json"
headers["Accept"] = %w(
application/vnd.docker.distribution.manifest.v2+json
application/vnd.docker.distribution.manifest.list.v2+json
application/json"
).join(",")
end
headers["Content-Type"] = "application/vnd.docker.distribution.manifest.v2+json" unless payload.nil?

Expand Down