Files
rengine/shared/http.py
T
Yogesh Ojha 69239333bc Refactor validation and DNS tools, implementation of onboarding wizard
- Added `clean_name` function to `validation.py` for name validation with max length.
- Simplified docstrings in `dnsx` client, parser, and service files for clarity.
- Enhanced error handling in `ViewDNSService` to prevent disabling keys on rate limits.
- Improved WHOIS service to handle concurrent inserts gracefully with integrity checks.
- Updated `Settings` class in worker config to inherit from `BaseAppSettings`.
- Added new dependencies in `pyproject.toml` for `apprise` and `cryptography`.
2026-06-21 21:56:20 +05:30

53 lines
1.3 KiB
Python

import os
import httpx
# TODO: dummy user agents
DEFAULT_TIMEOUT = 30
DEFAULT_USER_AGENT = (
"Mozilla/5.0 (compatible; reNgine/3.0; +https://github.com/yogeshojha/rengine)"
)
MAX_RETRIES = 3
def _get_proxy_url() -> str | None:
return os.environ.get("RENGINE_PROXY_URL")
def _get_timeout() -> float:
try:
return float(os.environ.get("RENGINE_HTTP_TIMEOUT", DEFAULT_TIMEOUT))
except (ValueError, TypeError):
return DEFAULT_TIMEOUT
def _get_user_agent() -> str:
return os.environ.get("RENGINE_USER_AGENT", DEFAULT_USER_AGENT)
def _base_kwargs() -> dict:
kwargs: dict = {
"timeout": httpx.Timeout(_get_timeout()),
"headers": {"User-Agent": _get_user_agent()},
"follow_redirects": True,
}
proxy = _get_proxy_url()
if proxy:
kwargs["proxy"] = proxy
return kwargs
def get_async_client(**overrides) -> httpx.AsyncClient:
kwargs = _base_kwargs()
kwargs["transport"] = httpx.AsyncHTTPTransport(retries=MAX_RETRIES)
kwargs.update(overrides)
return httpx.AsyncClient(**kwargs)
def get_sync_client(**overrides) -> httpx.Client:
kwargs = _base_kwargs()
kwargs["transport"] = httpx.HTTPTransport(retries=MAX_RETRIES)
kwargs.update(overrides)
return httpx.Client(**kwargs)