diff options
| author | Joel Kronqvist <joel.kronqvist@iki.fi> | 2026-10-13 20:44:39 +0300 |
|---|---|---|
| committer | Joel Kronqvist <joel.kronqvist@iki.fi> | 2026-10-13 20:44:39 +0300 |
| commit | 723cbece96ac139a91c9766dd8af846c13681dba (patch) | |
| tree | fa661cab8984bedfdd55a6316fb0bb54efbbe851 /web_utils.py | |
| parent | 94ac1e1b1df4ed6dbdf2f0f0d41cb6dce747cbf3 (diff) | |
| download | agent-723cbece96ac139a91c9766dd8af846c13681dba.tar.gz agent-723cbece96ac139a91c9766dd8af846c13681dba.zip | |
feat: socks5 proxy
Diffstat (limited to 'web_utils.py')
| -rw-r--r-- | web_utils.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/web_utils.py b/web_utils.py index 89c6632..1962489 100644 --- a/web_utils.py +++ b/web_utils.py @@ -1,7 +1,7 @@ import httpx2 import subprocess import re -from typing import Dict, Union +from typing import Dict, Optional, Union from dataclasses import dataclass @@ -44,14 +44,18 @@ def html_to_markdown(html: str) -> str: raise RuntimeError(f"Unexpected error during markdown conversion: {e}") -def fetch_and_markdownify(url: str) -> FetchResult: - """Fetches a web page and transforms it to markdown, with memoization.""" +def fetch_and_markdownify(url: str, proxy: Optional[str] = None) -> FetchResult: + """Fetches a web page and transforms it to markdown, with memoization. + + If `proxy` is given (e.g. 'socks5://host:1080'), the request is routed + through that SOCKS5 proxy. + """ if url in _cache: return _cache[url] try: with httpx2.Client( - headers={"User-Agent": "Mozilla/5.0"}, timeout=10.0 + headers={"User-Agent": "Mozilla/5.0"}, timeout=10.0, proxy=proxy ) as client: response = client.get(url) response.raise_for_status() |
