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

requests: set User-Agent to "ci" in a CI environment #523

Merged
merged 4 commits into from
Sep 27, 2023
Merged
Changes from 2 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
10 changes: 9 additions & 1 deletion bioimageio/spec/shared/_resolve_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,15 @@ def _download_url(uri: raw_nodes.URI, output: typing.Optional[os.PathLike] = Non
# download with tqdm adapted from:
# https://github.com/shaypal5/tqdl/blob/189f7fd07f265d29af796bee28e0893e1396d237/tqdl/core.py
# Streaming, so we can iterate over the response.
r = requests.get(str(uri), stream=True)
headers = {}
if os.environ.get("CI", "false").lower() in ("1", "t", "true", "yes", "y"):
FynnBe marked this conversation as resolved.
Show resolved Hide resolved
headers["User-Agent"] = "ci"

user_agent = os.environ.get("BIOIMAGEIO_USER_AGENT")
if user_agent is not None:
headers["User-Agent"] = user_agent
FynnBe marked this conversation as resolved.
Show resolved Hide resolved

r = requests.get(str(uri), stream=True, headers=headers)
r.raise_for_status()
# Total size in bytes.
total_size = int(r.headers.get("content-length", 0))
Expand Down
Loading