### Install httpx-secure Source: https://github.com/zaczero/httpx-secure/blob/main/README.md Installs the httpx-secure package using pip. This is the primary method for adding the library to your Python project. ```bash pip install httpx-secure ``` -------------------------------- ### Custom Domain Whitelisting with httpx-secure Source: https://github.com/zaczero/httpx-secure/blob/main/README.md Shows how to implement custom validation logic by providing a validator function to httpx_ssrf_protection. This example whitelists specific domains. ```python import httpx from httpx_secure import httpx_ssrf_protection from ipaddress import IPv4Address, IPv6Address def custom_validator( hostname: str, ip: IPv4Address | IPv6Address, port: int ) -> bool: return hostname in { "whitelisted.domain", "webhook.partner.com", } client = httpx_ssrf_protection( httpx.AsyncClient(), custom_validator=custom_validator, ) await client.get("https://whitelisted.domain") # Allowed await client.get("https://unknown.domain") # Blocked ``` -------------------------------- ### Basic SSRF Protection with httpx Source: https://github.com/zaczero/httpx-secure/blob/main/README.md Demonstrates how to wrap an httpx.AsyncClient with httpx_ssrf_protection for basic SSRF blocking. It includes configuration for DNS caching. ```python import httpx from httpx_secure import httpx_ssrf_protection client = httpx_ssrf_protection( httpx.AsyncClient(), dns_cache_size=1000, # Cache up to 1000 DNS resolutions dns_cache_ttl=600, # Cache for 10 minutes ) await client.get("https://public.domain") # Allowed await client.get("https://private.domain") # Blocked ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.