From b63accc1b881b0d0f8de82c5e416a1a38b54e457 Mon Sep 17 00:00:00 2001 From: SimonThordal Date: Mon, 15 Apr 2024 09:07:32 +0200 Subject: [PATCH] feat: proxy requests if requested --- yente/data/util.py | 4 +++- yente/settings.py | 4 ++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/yente/data/util.py b/yente/data/util.py index f5e534f8..b3f81f14 100644 --- a/yente/data/util.py +++ b/yente/data/util.py @@ -12,6 +12,7 @@ from rigour.text.distance import levenshtein from fingerprints import remove_types, clean_name_light from nomenklatura.util import fingerprint_name, names_word_list +from yente.settings import HTTP_PROXY @lru_cache(maxsize=5000) @@ -130,7 +131,8 @@ def get_url_local_path(url: str) -> Optional[Path]: @asynccontextmanager async def httpx_session() -> AsyncGenerator[httpx.AsyncClient, None]: transport = httpx.AsyncHTTPTransport(retries=3) + proxy = HTTP_PROXY if HTTP_PROXY != "" else None async with httpx.AsyncClient( - transport=transport, http2=True, timeout=None + transport=transport, http2=True, timeout=None, proxy=proxy ) as client: yield client diff --git a/yente/settings.py b/yente/settings.py index 3fcbbd33..2fa11a15 100644 --- a/yente/settings.py +++ b/yente/settings.py @@ -113,6 +113,10 @@ def env_str(name: str, default: str) -> str: "Cache-Control": "public; max-age=3600", "X-Robots-Tag": "none", } + +# Set a proxy for outgoing HTTP requests: +HTTP_PROXY = env_str("YENTE_HTTP_PROXY", "") + # How many results to return per page of search results max: MAX_PAGE = 500