From: Kar Petrosyan <92274156+karpetrosyan@users.noreply.github.com> Date: Thu, 13 Jun 2024 15:25:24 +0000 (+0400) Subject: Add documentation for socket_options X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=acd83dac70eb9df52518add421498959a5f157e7;p=thirdparty%2Fhttpx.git Add documentation for socket_options --- diff --git a/docs/advanced/network-options.md b/docs/advanced/network-options.md index 08329359..ea444d42 100644 --- a/docs/advanced/network-options.md +++ b/docs/advanced/network-options.md @@ -26,7 +26,18 @@ Configure the local address that the socket should be bound too. The most common ### `socket_options` -*TODO: Example* +Configure the list of socket options to be applied to the underlying sockets used for network connections. +For example, you can use it to explicitly specify which network interface should be used for the connection in this manner: + +```python +import httpx + +socket_options = [(socket.SOL_SOCKET, socket.SO_BINDTODEVICE, b"ETH999")] + +network_options = httpx.NetworkOptions( + socket_options=socket_options +) +``` ### `uds` diff --git a/httpx/_config.py b/httpx/_config.py index 736cfdf3..168b4438 100644 --- a/httpx/_config.py +++ b/httpx/_config.py @@ -14,7 +14,7 @@ from ._types import CertTypes, HeaderTypes, TimeoutTypes, URLTypes, VerifyTypes from ._urls import URL from ._utils import get_ca_bundle_from_env -__all__ = ["Limits", "Proxy", "Timeout", "create_ssl_context"] +__all__ = ["Limits", "Proxy", "Timeout", "NetworkOptions", "create_ssl_context"] SOCKET_OPTION = typing.Union[ typing.Tuple[int, int, int],