Validate if a URL is accessible.
(url: HttpUrl)
| 113 | |
| 114 | @router.post("/validate-url") |
| 115 | async def validate_url(url: HttpUrl): |
| 116 | """Validate if a URL is accessible.""" |
| 117 | try: |
| 118 | import httpx |
| 119 | async with httpx.AsyncClient(timeout=10.0) as client: |
| 120 | response = await client.head(str(url), follow_redirects=True) |
| 121 | |
| 122 | return { |
| 123 | "url": str(url), |
| 124 | "valid": response.status_code < 400, |
| 125 | "status_code": response.status_code, |
| 126 | "content_type": response.headers.get("content-type", "") |
| 127 | } |
| 128 | except Exception as e: |
| 129 | return { |
| 130 | "url": str(url), |
| 131 | "valid": False, |
| 132 | "error": str(e) |
| 133 | } |
| 134 | |
| 135 | @router.post("/preview") |
| 136 | async def preview_scraping(url: HttpUrl, selector: Optional[str] = None): |
nothing calls this directly
no outgoing calls
no test coverage detected