Skip to content

hyperion.adapters.http.proxy

hyperion.adapters.http.proxy

HTTP proxy helpers (lite -- httpx only).

redact_url

redact_url(url, replace='***')

Replace password from {url} (if any) with {replace}. If the url contains no password, url is returned unchanged.

Source code in hyperion/adapters/http/proxy.py
def redact_url(url: str, replace: str = "***") -> str:
    """Replace password from {url} (if any) with {replace}.
    If the url contains no password, url is returned unchanged.
    """
    parsed = urlparse(url)
    if parsed.password:
        return parsed._replace(netloc=f"{parsed.username}:{replace}@{parsed.hostname}").geturl()
    return url

get_proxy_mounts

get_proxy_mounts()

Build httpx proxy mounts from HYPERION_HTTP_PROXY_HTTP / HYPERION_HTTP_PROXY_HTTPS env vars.

If only one of the two is set, it is used for both http:// and https://.

Source code in hyperion/adapters/http/proxy.py
def get_proxy_mounts() -> dict[str, httpx.AsyncHTTPTransport]:
    """Build httpx proxy mounts from HYPERION_HTTP_PROXY_HTTP / HYPERION_HTTP_PROXY_HTTPS env vars.

    If only one of the two is set, it is used for both http:// and https://.
    """
    proxy_mounts: dict[str, httpx.AsyncHTTPTransport] = {}
    if http_config.proxy_http:
        redacted_url = redact_url(http_config.proxy_http)
        logger.info("Configuring HTTP proxy for http://", proxy_url=redacted_url)
        proxy_mounts["http://"] = httpx.AsyncHTTPTransport(proxy=http_config.proxy_http)
        if not http_config.proxy_https:
            logger.info("Configuring HTTP proxy for https://", proxy_url=redacted_url)
            proxy_mounts["https://"] = httpx.AsyncHTTPTransport(proxy=http_config.proxy_http)
    if http_config.proxy_https:
        redacted_url = redact_url(http_config.proxy_https)
        logger.info("Configuring HTTP proxy for https://", proxy_url=redacted_url)
        proxy_mounts["https://"] = httpx.AsyncHTTPTransport(proxy=http_config.proxy_https)
        if not http_config.proxy_http:
            logger.info("Configuring HTTP proxy for http://", proxy_url=redacted_url)
            proxy_mounts["http://"] = httpx.AsyncHTTPTransport(proxy=http_config.proxy_https)
    return proxy_mounts