Skip to content

Commit

Permalink
Merge pull request #424 from jthiltges/mimetype
Browse files Browse the repository at this point in the history
Set more MIME types when requesting manifest
  • Loading branch information
djw8605 committed Mar 31, 2023
2 parents 040d0ca + ada86f0 commit 7ee6589
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions dockerhub.py
Original file line number Diff line number Diff line change
Expand Up @@ -513,20 +513,28 @@ def manifest(self, user, repository, tag, head=False, **kwargs):
"""
url = self._api_url('{0}/{1}/manifests/{2}'.format(user, repository, tag))

manifest_mime = ', '.join((
'application/vnd.docker.distribution.manifest.v1+json',
'application/vnd.docker.distribution.manifest.v2+json',
'application/vnd.docker.distribution.manifest.list.v2+json',
'application/vnd.oci.image.manifest.v1+json',
'application/vnd.oci.image.index.v1+json',
))

#Added support to retrieve oci images for hub.opensciencegrid.org
#https://gitlab.com/gitlab-org/gitlab-foss/-/merge_requests/31127
headers_has_accept = False
if 'headers' not in kwargs:
kwargs['headers'] = {'ACCEPT' : 'application/vnd.oci.image.manifest.v1+json'}
kwargs['headers'] = {'ACCEPT': manifest_mime}
else:
for headers_key in kwargs['headers'].keys():
if 'accept' in headers_key.casefold():
headers_has_accept = True
kwargs['headers'][headers_key]+=', application/vnd.oci.image.manifest.v1+json'
kwargs['headers'][headers_key]+=', ' + manifest_mime
break
if not headers_has_accept:
kwargs['headers']['ACCEPT'] = 'application/vnd.oci.image.manifest.v1+json'
kwargs['headers']['ACCEPT'] = manifest_mime

if head:
return self._do_requests_head(url, **kwargs)
Expand Down

0 comments on commit 7ee6589

Please sign in to comment.