Skip to content

Commit 8601d4d

Browse files
committed
Added max-redirects
1 parent a5e3404 commit 8601d4d

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

scripts/curl_wrapper.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ def __init__(
3333
user_agent: str = DEFAULT_USER_AGENT,
3434
connect_timeout: int = 5,
3535
max_time: int = 10,
36+
max_redirects: int = 3,
3637
) -> None:
3738
self.url = url
3839
self._stderr: Optional[str] = None
@@ -41,14 +42,20 @@ def __init__(
4142
[
4243
"curl",
4344
"-sSf",
45+
"-L", # follow redirects
46+
"--max-redirs",
47+
f"{max_redirects}", # limit number of redirects
48+
# "--proto", "=https", # (optional) only allow https for the initial URL
49+
"--proto-redir",
50+
"=all,https", # only allow https after redirects; http will fail
4451
"--output",
45-
"-",
52+
"-", # discard body
4653
"--connect-timeout",
47-
str(connect_timeout),
54+
f"{connect_timeout}",
4855
"--max-time",
49-
str(max_time),
56+
f"{max_time}",
5057
"--user-agent",
51-
user_agent,
58+
f"{user_agent}",
5259
self.url,
5360
],
5461
stdout=open(os.devnull, "w"),

0 commit comments

Comments
 (0)