Skip to content

Commit 60508de

Browse files
karpetrosyansamclearman
authored andcommitted
Add socket_options argument to httpx.HTTPTransport class (encode#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
1 parent 940fb7b commit 60508de

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
66

77
## Unreleased
88

9+
### Added
10+
11+
* Add `socket_options` argument to `httpx.HTTPTransport` and `httpx.AsyncHTTPTransport` classes. (#2716)
12+
913
### Fixed
1014

1115
* Return `500` error response instead of exceptions when `raise_app_exceptions=False` is set on `ASGITransport`. (#2669)

httpx/_transports/default.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,12 @@
5353
T = typing.TypeVar("T", bound="HTTPTransport")
5454
A = typing.TypeVar("A", bound="AsyncHTTPTransport")
5555

56+
SOCKET_OPTION = typing.Union[
57+
typing.Tuple[int, int, int],
58+
typing.Tuple[int, int, typing.Union[bytes, bytearray]],
59+
typing.Tuple[int, int, None, int],
60+
]
61+
5662

5763
@contextlib.contextmanager
5864
def map_httpcore_exceptions() -> typing.Iterator[None]:
@@ -122,6 +128,7 @@ def __init__(
122128
uds: typing.Optional[str] = None,
123129
local_address: typing.Optional[str] = None,
124130
retries: int = 0,
131+
socket_options: typing.Optional[typing.Iterable[SOCKET_OPTION]] = None,
125132
) -> None:
126133
ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)
127134

@@ -136,6 +143,7 @@ def __init__(
136143
uds=uds,
137144
local_address=local_address,
138145
retries=retries,
146+
socket_options=socket_options,
139147
)
140148
elif proxy.url.scheme in ("http", "https"):
141149
self._pool = httpcore.HTTPProxy(
@@ -153,6 +161,7 @@ def __init__(
153161
keepalive_expiry=limits.keepalive_expiry,
154162
http1=http1,
155163
http2=http2,
164+
socket_options=socket_options,
156165
)
157166
elif proxy.url.scheme == "socks5":
158167
try:
@@ -257,6 +266,7 @@ def __init__(
257266
uds: typing.Optional[str] = None,
258267
local_address: typing.Optional[str] = None,
259268
retries: int = 0,
269+
socket_options: typing.Optional[typing.Iterable[SOCKET_OPTION]] = None,
260270
) -> None:
261271
ssl_context = create_ssl_context(verify=verify, cert=cert, trust_env=trust_env)
262272

@@ -271,6 +281,7 @@ def __init__(
271281
uds=uds,
272282
local_address=local_address,
273283
retries=retries,
284+
socket_options=socket_options,
274285
)
275286
elif proxy.url.scheme in ("http", "https"):
276287
self._pool = httpcore.AsyncHTTPProxy(
@@ -288,6 +299,7 @@ def __init__(
288299
keepalive_expiry=limits.keepalive_expiry,
289300
http1=http1,
290301
http2=http2,
302+
socket_options=socket_options,
291303
)
292304
elif proxy.url.scheme == "socks5":
293305
try:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ classifiers = [
2929
]
3030
dependencies = [
3131
"certifi",
32-
"httpcore>=0.15.0,<0.18.0",
32+
"httpcore>=0.17.2,<0.18.0",
3333
"idna",
3434
"sniffio",
3535
]

0 commit comments

Comments
 (0)