MCPcopy Create free account
hub / github.com/github/spec-kit / _safe_fetch

Function _safe_fetch

src/specify_cli/workflows/_commands.py:1234–1251  ·  view source on GitHub ↗
(url: str)

Source from the content-addressed store, hash-verified

1232 from specify_cli.authentication.http import open_url as _open_url
1233
1234 def _safe_fetch(url: str) -> bytes:
1235 parsed = urlparse(url)
1236 is_localhost = parsed.hostname in ("localhost", "127.0.0.1", "::1")
1237 if parsed.scheme != "https" and not (parsed.scheme == "http" and is_localhost):
1238 raise ValueError(f"Refusing to fetch from non-HTTPS URL: {url}")
1239 if not parsed.hostname:
1240 raise ValueError(f"Refusing to fetch from URL with no hostname: {url}")
1241 with _open_url(url, timeout=30) as resp:
1242 final_url = resp.geturl()
1243 final_parsed = urlparse(final_url)
1244 final_is_localhost = final_parsed.hostname in ("localhost", "127.0.0.1", "::1")
1245 if final_parsed.scheme != "https" and not (
1246 final_parsed.scheme == "http" and final_is_localhost
1247 ):
1248 raise ValueError(f"Redirect to non-HTTPS URL: {final_url}")
1249 if not final_parsed.hostname:
1250 raise ValueError(f"Redirect to URL with no hostname: {final_url}")
1251 return resp.read()
1252
1253 _validate_step_id_or_exit(step_id)
1254

Callers 1

workflow_step_addFunction · 0.85

Calls 2

geturlMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected