Skip to content

Commit

Permalink
Merge pull request #523 from bioimage-io/ci_user_agent
Browse files Browse the repository at this point in the history
requests: set User-Agent to "ci"  in a CI environment
  • Loading branch information
FynnBe authored Sep 27, 2023
2 parents 451cf4e + 0ec5f28 commit 91ea364
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion bioimageio/spec/VERSION
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"version": "0.4.9"
"version": "0.4.9post1"
}
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"):
headers["User-Agent"] = "ci"

user_agent = os.environ.get("BIOIMAGEIO_USER_AGENT")
if user_agent is not None:
headers["User-Agent"] = user_agent

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

0 comments on commit 91ea364

Please sign in to comment.