Skip to content

Commit

Permalink
Resolve DOI more cleanly
Browse files Browse the repository at this point in the history
Using doi.org, we only care to find out *where* the doi is
pointing to. We don't need to go fetch the contents of that page
fully.
  • Loading branch information
yuvipanda committed Dec 14, 2024
1 parent 8a6eb6b commit 7f980f4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions repo2docker/contentproviders/doi.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ def doi2url(self, doi):
doi = normalize_doi(doi)

try:
resp = self._request(f"https://doi.org/{doi}")
# We don't need to fetch the *contents* of the page the doi resolves to -
# only need to know what it redirects to.
resp = self._request(f"https://doi.org/{doi}", allow_redirects=False)
resp.raise_for_status()
except HTTPError as e:
# If the DOI doesn't exist, just return URL
Expand All @@ -60,7 +62,7 @@ def doi2url(self, doi):
# default Git provider as this leads to a misleading error.
self.log.error(f"DOI {doi} does not resolve: {e}")
raise
return resp.url
return resp.headers['Location']
else:
# Just return what is actulally just a URL
return doi
Expand Down

0 comments on commit 7f980f4

Please sign in to comment.