Server-side URL probe. Attempts a HEAD request first to avoid downloading the body. Some servers do not support HEAD; in that case, fall back to a streamed GET to obtain only the status code.
(url: str)
| 27 | |
| 28 | @router.get("/probe") |
| 29 | async def probe_url(url: str) -> dict[str, Any]: |
| 30 | """Server-side URL probe. |
| 31 | |
| 32 | Attempts a HEAD request first to avoid downloading the body. |
| 33 | Some servers do not support HEAD; in that case, fall back to a |
| 34 | streamed GET to obtain only the status code. |
| 35 | """ |
| 36 | status_code: int | None = None |
| 37 | try: |
| 38 | async with httpx.AsyncClient(follow_redirects=True, timeout=8.0) as client: |
| 39 | try: |
| 40 | resp = await client.request("HEAD", url) |
| 41 | status_code = int(resp.status_code) |
| 42 | except Exception: |
| 43 | # Fall back to a minimal GET (streamed, do not read body) |
| 44 | try: |
| 45 | async with client.stream("GET", url) as resp2: |
| 46 | status_code = int(resp2.status_code) |
| 47 | except Exception: |
| 48 | status_code = None |
| 49 | except Exception: |
| 50 | status_code = None |
| 51 | |
| 52 | return {"ok": status_code is not None, "status": status_code} |
| 53 | |
| 54 | |
| 55 | @router.post("/sync") |
nothing calls this directly
no outgoing calls
no test coverage detected