Add socket_options argument to httpx.HTTPTransport class (#2716)
* Add `socket_options` argument to `httpx.HTTPTransport` and `httpx.AsyncHTTPTransport` classes * Update changelog * Fix changelog format * Set httpcore's minimum version to 0.17.2 * Remove SOCKET_OPTIONS import
This commit is contained in:
parent
a682f6f1c7
commit
733595037a
@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||
|
||||
## Unreleased
|
||||
|
||||
### Added
|
||||
|
||||
* Add `socket_options` argument to `httpx.HTTPTransport` and `httpx.AsyncHTTPTransport` classes. (#2716)
|
||||
|
||||
### Fixed
|
||||
|
||||
* Return `500` error response instead of exceptions when `raise_app_exceptions=False` is set on `ASGITransport`. (#2669)
|
||||
|
||||
@ -53,6 +53,12 @@ from .base import AsyncBaseTransport, BaseTransport
|
||||
T = typing.TypeVar("T", bound="HTTPTransport")
|
||||
A = typing.TypeVar("A", bound="AsyncHTTPTransport")
|
||||
|
||||
SOCKET_OPTION = typing.Union[
|
||||
typing.Tuple[int, int, int],
|
||||
typing.Tuple[int, int, typing.Union[bytes, bytearray]],
|
||||
typing.Tuple[int, int, None, int],
|
||||
]
|
||||
|
||||
|
||||
@contextlib.contextmanager
|
||||
def map_httpcore_exceptions() -> typing.Iterator[None]:
|
||||
@ -122,6 +128,7 @@ class HTTPTransport(BaseTransport):
|
||||
uds: typing.Optional[str] = None,
|
||||
local_address: typing.Optional[str] = None,
|
||||
retries: int = 0,
|
||||
socket_options: typing.Optional[typing.Iterable[SOCKET_OPTION]] = None,
|
||||
) -> None:
|
||||
ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)
|
||||
|
||||
@ -136,6 +143,7 @@ class HTTPTransport(BaseTransport):
|
||||
uds=uds,
|
||||
local_address=local_address,
|
||||
retries=retries,
|
||||
socket_options=socket_options,
|
||||
)
|
||||
elif proxy.url.scheme in ("http", "https"):
|
||||
self._pool = httpcore.HTTPProxy(
|
||||
@ -153,6 +161,7 @@ class HTTPTransport(BaseTransport):
|
||||
keepalive_expiry=limits.keepalive_expiry,
|
||||
http1=http1,
|
||||
http2=http2,
|
||||
socket_options=socket_options,
|
||||
)
|
||||
elif proxy.url.scheme == "socks5":
|
||||
try:
|
||||
@ -257,6 +266,7 @@ class AsyncHTTPTransport(AsyncBaseTransport):
|
||||
uds: typing.Optional[str] = None,
|
||||
local_address: typing.Optional[str] = None,
|
||||
retries: int = 0,
|
||||
socket_options: typing.Optional[typing.Iterable[SOCKET_OPTION]] = None,
|
||||
) -> None:
|
||||
ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)
|
||||
|
||||
@ -271,6 +281,7 @@ class AsyncHTTPTransport(AsyncBaseTransport):
|
||||
uds=uds,
|
||||
local_address=local_address,
|
||||
retries=retries,
|
||||
socket_options=socket_options,
|
||||
)
|
||||
elif proxy.url.scheme in ("http", "https"):
|
||||
self._pool = httpcore.AsyncHTTPProxy(
|
||||
@ -288,6 +299,7 @@ class AsyncHTTPTransport(AsyncBaseTransport):
|
||||
keepalive_expiry=limits.keepalive_expiry,
|
||||
http1=http1,
|
||||
http2=http2,
|
||||
socket_options=socket_options,
|
||||
)
|
||||
elif proxy.url.scheme == "socks5":
|
||||
try:
|
||||
|
||||
@ -29,7 +29,7 @@ classifiers = [
|
||||
]
|
||||
dependencies = [
|
||||
"certifi",
|
||||
"httpcore>=0.15.0,<0.18.0",
|
||||
"httpcore>=0.17.2,<0.18.0",
|
||||
"idna",
|
||||
"sniffio",
|
||||
]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user