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

refactor: Pass Accept header to requests in contrib.utils.download #1673

Merged
merged 6 commits into from
Nov 1, 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
13 changes: 12 additions & 1 deletion src/pyhf/contrib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,18 @@ def download(archive_url, output_directory, force=False, compress=False):
+ "To download an archive from this host use the --force option."
)

with requests.get(archive_url) as response:
# c.f. https://github.com/scikit-hep/pyhf/issues/1491
# > Use content negotiation at the landing page for the resource that
# > the DOI resolves to. DataCite content negotiation is forwarding all
# > requests with unknown content types to the URL registered in the
# > handle system.
# c.f. https://blog.datacite.org/changes-to-doi-content-negotiation/
# The HEPData landing page for the resource file can check if the Accept
# request HTTP header matches the content type of the resource file and
# return the content directly if so.
with requests.get(
archive_url, headers={"Accept": "application/x-tar"}
) as response:
if compress:
with open(output_directory, "wb") as archive:
archive.write(response.content)
Expand Down