Skip to content

Commit

Permalink
feat: proxy requests if requested
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonThordal committed Apr 15, 2024
1 parent e621ca1 commit b63accc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion yente/data/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
4 changes: 4 additions & 0 deletions yente/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit b63accc

Please sign in to comment.