httpx2 2.15.1__tar.gz → 2.16.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {httpx2-2.15.1 → httpx2-2.16.1}/CHANGELOG.md +23 -0
  2. {httpx2-2.15.1 → httpx2-2.16.1}/PKG-INFO +13 -7
  3. {httpx2-2.15.1 → httpx2-2.16.1}/README.md +4 -2
  4. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/__init__.py +1 -1
  5. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_api.py +8 -8
  6. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_auth.py +14 -14
  7. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_client.py +57 -63
  8. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_config.py +6 -6
  9. httpx2-2.16.1/httpx2/_cookies.py +74 -0
  10. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_decoders.py +28 -27
  11. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_exceptions.py +2 -2
  12. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_main.py +12 -11
  13. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_models.py +54 -40
  14. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_multipart.py +12 -11
  15. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_status_codes.py +2 -1
  16. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_transports/asgi.py +10 -9
  17. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_transports/base.py +3 -7
  18. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_transports/default.py +13 -16
  19. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_transports/mock.py +3 -3
  20. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_transports/wsgi.py +9 -8
  21. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_types.py +31 -29
  22. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_urlparse.py +6 -6
  23. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_urls.py +22 -21
  24. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_utils.py +12 -8
  25. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/websockets/_api.py +20 -21
  26. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/websockets/_exceptions.py +2 -2
  27. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/websockets/_transport.py +9 -10
  28. {httpx2-2.15.1 → httpx2-2.16.1}/.gitignore +0 -0
  29. {httpx2-2.15.1 → httpx2-2.16.1}/LICENSE.md +0 -0
  30. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/__version__.py +0 -0
  31. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_alias.py +0 -0
  32. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_content.py +0 -0
  33. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_sse.py +0 -0
  34. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/_transports/__init__.py +1 -1
  35. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/py.typed +0 -0
  36. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/websockets/__init__.py +0 -0
  37. {httpx2-2.15.1 → httpx2-2.16.1}/httpx2/websockets/_ping.py +0 -0
  38. {httpx2-2.15.1 → httpx2-2.16.1}/pyproject.toml +0 -0
@@ -4,6 +4,29 @@ All notable changes to this project will be documented in this file.
4
4
 
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
6
6
 
7
+ ## 2.16.1 (November 16th, 2026)
8
+
9
+ ### Fixed
10
+
11
+ * Return the response when a redirect has an invalid `Location` header and redirects are not followed, instead of raising `RemoteProtocolError`. `response.next_request` is `None` in that case.
12
+ ([#1064](https://github.com/pydantic/httpx2/pull/1064))
13
+ * Match subdomains for `NO_PROXY` entries written as `*.example.com`, the same as `.example.com`. The entry never matched before, so those requests still went through the proxy.
14
+ ([#1277](https://github.com/pydantic/httpx2/pull/1277))
15
+ * Parse Digest challenge parameter names case-insensitively, and allow whitespace around `=`. A challenge such as `Digest Realm="r", Nonce="n"` raised `ProtocolError` before.
16
+ ([#1315](https://github.com/pydantic/httpx2/pull/1315))
17
+
18
+ ## 2.16.0 (October 21st, 2026)
19
+
20
+ ### Changed
21
+
22
+ * Look up only the cookie domains that match the request host, and skip the expired cookie sweep until a cookie is due. With 1,000 cookies across 500 domains, building the `Cookie` header is about 18 times faster. Cookies from different domains are now sent from the least to the most specific domain.
23
+ ([#1285](https://github.com/pydantic/httpx2/pull/1285))
24
+
25
+ ### Fixed
26
+
27
+ * Reuse the client cookie jar instead of copying it on every request and redirect. A custom policy set with `client.cookies.jar.set_policy()` now applies to outgoing requests.
28
+ ([#1284](https://github.com/pydantic/httpx2/pull/1284))
29
+
7
30
  ## 2.15.1 (October 19th, 2026)
8
31
 
9
32
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: httpx2
3
- Version: 2.15.1
3
+ Version: 2.16.1
4
4
  Summary: The next generation HTTP client.
5
5
  Project-URL: Changelog, https://github.com/pydantic/httpx2/blob/main/src/httpx2/CHANGELOG.md
6
6
  Project-URL: Homepage, https://github.com/pydantic/httpx2
@@ -26,7 +26,7 @@ Classifier: Programming Language :: Python :: 3.15
26
26
  Classifier: Topic :: Internet :: WWW/HTTP
27
27
  Requires-Python: >=3.11
28
28
  Requires-Dist: anyio>=4.10; sys_platform != 'emscripten'
29
- Requires-Dist: httpcore2==2.15.1; sys_platform != 'emscripten'
29
+ Requires-Dist: httpcore2==2.16.1; sys_platform != 'emscripten'
30
30
  Requires-Dist: httpx2-jsfetch; sys_platform == 'emscripten' and python_version >= '3.12'
31
31
  Requires-Dist: idna>=3.18
32
32
  Requires-Dist: truststore>=0.10; sys_platform != 'emscripten'
@@ -58,7 +58,7 @@ Description-Content-Type: text/markdown
58
58
  <a href="https://pydantic.dev/docs/logfire/join-slack/"><img src="https://img.shields.io/badge/Slack-Join%20Slack-4A154B?logo=slack" alt="Join Slack"></a>
59
59
  </p>
60
60
 
61
- HTTPX2 is a fully featured HTTP client library for Python. It includes **an integrated command line client**, has support for both **HTTP/1.1 and HTTP/2**, and provides both **sync and async APIs**.
61
+ HTTPX2 is a fully featured HTTP client library for Python. It includes **an integrated command line client**, has support for both **HTTP/1.1 and HTTP/2**, supports **WebSockets**, and provides both **sync and async APIs**.
62
62
 
63
63
  > [!NOTE]
64
64
  > HTTPX2 is a continuation of the wonderful work started by [@lovelydinosaur](https://github.com/lovelydinosaur) and the broader HTTPX community. We're enormously grateful for everything that has gone into HTTPX over the years - it has been a foundational piece of the modern Python ecosystem, and this project would not exist without it.
@@ -108,6 +108,7 @@ HTTPX2 builds on the well-established usability of `requests`, and gives you:
108
108
  * An integrated command-line client.
109
109
  * HTTP/1.1 [and HTTP/2 support](https://pydantic.dev/docs/httpx2/guides/http2/).
110
110
  * Standard synchronous interface, but with [async support if you need it](https://pydantic.dev/docs/httpx2/guides/async/).
111
+ * [WebSocket support](https://pydantic.dev/docs/httpx2/guides/websockets/).
111
112
  * Ability to make requests directly to [WSGI applications](https://pydantic.dev/docs/httpx2/advanced/transports/#wsgi-transport) or [ASGI applications](https://pydantic.dev/docs/httpx2/advanced/transports/#asgi-transport).
112
113
  * Strict timeouts everywhere.
113
114
  * Fully type annotated.
@@ -151,7 +152,7 @@ Project documentation is available at [https://pydantic.dev/docs/httpx2/](https:
151
152
 
152
153
  For a run-through of all the basics, head over to the [QuickStart](https://pydantic.dev/docs/httpx2/get-started/quickstart/).
153
154
 
154
- For more advanced topics, see the [Advanced Usage](https://pydantic.dev/docs/httpx2/advanced/clients/) section, the [async support](https://pydantic.dev/docs/httpx2/guides/async/) section, or the [HTTP/2](https://pydantic.dev/docs/httpx2/guides/http2/) section.
155
+ For more advanced topics, see the [Advanced Usage](https://pydantic.dev/docs/httpx2/advanced/clients/) section, the [async support](https://pydantic.dev/docs/httpx2/guides/async/) section, the [HTTP/2](https://pydantic.dev/docs/httpx2/guides/http2/) section, or the [WebSockets](https://pydantic.dev/docs/httpx2/guides/websockets/) section.
155
156
 
156
157
  The [Developer Interface](https://pydantic.dev/docs/httpx2/api/api/) provides a comprehensive API reference.
157
158
 
@@ -197,6 +198,7 @@ As well as these optional installs:
197
198
 
198
199
  * `h2` - HTTP/2 support. *(Optional, with `httpx2[http2]`)*
199
200
  * `socksio` - SOCKS proxy support. *(Optional, with `httpx2[socks]`)*
201
+ * `wsproto` - WebSocket support. *(Optional, with `httpx2[ws]`)*
200
202
  * `rich` - Rich terminal support. *(Optional, with `httpx2[cli]`)*
201
203
  * `click` - Command line client support. *(Optional, with `httpx2[cli]`)*
202
204
  * `brotli` or `brotlicffi` - Decoding for "brotli" compressed responses. *(Optional, with `httpx2[brotli]`)*
@@ -212,12 +214,16 @@ inspiration around the lower-level networking details.
212
214
 
213
215
  ## Release Information
214
216
 
215
- ## 2.15.1 (October 19th, 2026)
217
+ ## 2.16.1 (November 16th, 2026)
216
218
 
217
219
  ### Fixed
218
220
 
219
- * Configure the default SSL context once on Linux, instead of on every handshake. With OpenSSL older than 3.4, CPU usage grew over the lifetime of a reused client.
220
- ([#1253](https://github.com/pydantic/httpx2/pull/1253))
221
+ * Return the response when a redirect has an invalid `Location` header and redirects are not followed, instead of raising `RemoteProtocolError`. `response.next_request` is `None` in that case.
222
+ ([#1064](https://github.com/pydantic/httpx2/pull/1064))
223
+ * Match subdomains for `NO_PROXY` entries written as `*.example.com`, the same as `.example.com`. The entry never matched before, so those requests still went through the proxy.
224
+ ([#1277](https://github.com/pydantic/httpx2/pull/1277))
225
+ * Parse Digest challenge parameter names case-insensitively, and allow whitespace around `=`. A challenge such as `Digest Realm="r", Nonce="n"` raised `ProtocolError` before.
226
+ ([#1315](https://github.com/pydantic/httpx2/pull/1315))
221
227
 
222
228
  ---
223
229
 
@@ -8,7 +8,7 @@
8
8
  <a href="https://pydantic.dev/docs/logfire/join-slack/"><img src="https://img.shields.io/badge/Slack-Join%20Slack-4A154B?logo=slack" alt="Join Slack"></a>
9
9
  </p>
10
10
 
11
- HTTPX2 is a fully featured HTTP client library for Python. It includes **an integrated command line client**, has support for both **HTTP/1.1 and HTTP/2**, and provides both **sync and async APIs**.
11
+ HTTPX2 is a fully featured HTTP client library for Python. It includes **an integrated command line client**, has support for both **HTTP/1.1 and HTTP/2**, supports **WebSockets**, and provides both **sync and async APIs**.
12
12
 
13
13
  > [!NOTE]
14
14
  > HTTPX2 is a continuation of the wonderful work started by [@lovelydinosaur](https://github.com/lovelydinosaur) and the broader HTTPX community. We're enormously grateful for everything that has gone into HTTPX over the years - it has been a foundational piece of the modern Python ecosystem, and this project would not exist without it.
@@ -58,6 +58,7 @@ HTTPX2 builds on the well-established usability of `requests`, and gives you:
58
58
  * An integrated command-line client.
59
59
  * HTTP/1.1 [and HTTP/2 support](https://pydantic.dev/docs/httpx2/guides/http2/).
60
60
  * Standard synchronous interface, but with [async support if you need it](https://pydantic.dev/docs/httpx2/guides/async/).
61
+ * [WebSocket support](https://pydantic.dev/docs/httpx2/guides/websockets/).
61
62
  * Ability to make requests directly to [WSGI applications](https://pydantic.dev/docs/httpx2/advanced/transports/#wsgi-transport) or [ASGI applications](https://pydantic.dev/docs/httpx2/advanced/transports/#asgi-transport).
62
63
  * Strict timeouts everywhere.
63
64
  * Fully type annotated.
@@ -101,7 +102,7 @@ Project documentation is available at [https://pydantic.dev/docs/httpx2/](https:
101
102
 
102
103
  For a run-through of all the basics, head over to the [QuickStart](https://pydantic.dev/docs/httpx2/get-started/quickstart/).
103
104
 
104
- For more advanced topics, see the [Advanced Usage](https://pydantic.dev/docs/httpx2/advanced/clients/) section, the [async support](https://pydantic.dev/docs/httpx2/guides/async/) section, or the [HTTP/2](https://pydantic.dev/docs/httpx2/guides/http2/) section.
105
+ For more advanced topics, see the [Advanced Usage](https://pydantic.dev/docs/httpx2/advanced/clients/) section, the [async support](https://pydantic.dev/docs/httpx2/guides/async/) section, the [HTTP/2](https://pydantic.dev/docs/httpx2/guides/http2/) section, or the [WebSockets](https://pydantic.dev/docs/httpx2/guides/websockets/) section.
105
106
 
106
107
  The [Developer Interface](https://pydantic.dev/docs/httpx2/api/api/) provides a comprehensive API reference.
107
108
 
@@ -147,6 +148,7 @@ As well as these optional installs:
147
148
 
148
149
  * `h2` - HTTP/2 support. *(Optional, with `httpx2[http2]`)*
149
150
  * `socksio` - SOCKS proxy support. *(Optional, with `httpx2[socks]`)*
151
+ * `wsproto` - WebSocket support. *(Optional, with `httpx2[ws]`)*
150
152
  * `rich` - Rich terminal support. *(Optional, with `httpx2[cli]`)*
151
153
  * `click` - Command line client support. *(Optional, with `httpx2[cli]`)*
152
154
  * `brotli` or `brotlicffi` - Decoding for "brotli" compressed responses. *(Optional, with `httpx2[brotli]`)*
@@ -13,7 +13,7 @@ from ._transports import *
13
13
  from ._types import *
14
14
  from ._urls import *
15
15
 
16
- __all__ = [
16
+ __all__ = [ # noqa: RUF022
17
17
  # __version__.py
18
18
  "__description__",
19
19
  "__title__",
@@ -1,8 +1,8 @@
1
1
  from __future__ import annotations
2
2
 
3
- import typing
4
3
  from collections.abc import Generator
5
4
  from contextlib import contextmanager
5
+ from typing import TYPE_CHECKING, Any
6
6
 
7
7
  from ._client import Client
8
8
  from ._config import (
@@ -26,7 +26,7 @@ from ._types import (
26
26
  )
27
27
  from ._urls import URL
28
28
 
29
- if typing.TYPE_CHECKING:
29
+ if TYPE_CHECKING:
30
30
  import ssl # pragma: no cover
31
31
 
32
32
  from .websockets._api import WebSocketSession
@@ -55,7 +55,7 @@ def request(
55
55
  content: RequestContent | None = None,
56
56
  data: RequestData | None = None,
57
57
  files: RequestFiles | None = None,
58
- json: typing.Any | None = None,
58
+ json: Any | None = None,
59
59
  headers: HeaderTypes | None = None,
60
60
  cookies: CookieTypes | None = None,
61
61
  auth: AuthTypes | None = None,
@@ -128,7 +128,7 @@ def stream(
128
128
  content: RequestContent | None = None,
129
129
  data: RequestData | None = None,
130
130
  files: RequestFiles | None = None,
131
- json: typing.Any | None = None,
131
+ json: Any | None = None,
132
132
  headers: HeaderTypes | None = None,
133
133
  cookies: CookieTypes | None = None,
134
134
  auth: AuthTypes | None = None,
@@ -284,7 +284,7 @@ def post(
284
284
  content: RequestContent | None = None,
285
285
  data: RequestData | None = None,
286
286
  files: RequestFiles | None = None,
287
- json: typing.Any | None = None,
287
+ json: Any | None = None,
288
288
  params: QueryParamTypes | None = None,
289
289
  headers: HeaderTypes | None = None,
290
290
  cookies: CookieTypes | None = None,
@@ -325,7 +325,7 @@ def put(
325
325
  content: RequestContent | None = None,
326
326
  data: RequestData | None = None,
327
327
  files: RequestFiles | None = None,
328
- json: typing.Any | None = None,
328
+ json: Any | None = None,
329
329
  params: QueryParamTypes | None = None,
330
330
  headers: HeaderTypes | None = None,
331
331
  cookies: CookieTypes | None = None,
@@ -366,7 +366,7 @@ def patch(
366
366
  content: RequestContent | None = None,
367
367
  data: RequestData | None = None,
368
368
  files: RequestFiles | None = None,
369
- json: typing.Any | None = None,
369
+ json: Any | None = None,
370
370
  params: QueryParamTypes | None = None,
371
371
  headers: HeaderTypes | None = None,
372
372
  cookies: CookieTypes | None = None,
@@ -443,7 +443,7 @@ def query(
443
443
  content: RequestContent | None = None,
444
444
  data: RequestData | None = None,
445
445
  files: RequestFiles | None = None,
446
- json: typing.Any | None = None,
446
+ json: Any | None = None,
447
447
  params: QueryParamTypes | None = None,
448
448
  headers: HeaderTypes | None = None,
449
449
  cookies: CookieTypes | None = None,
@@ -4,16 +4,16 @@ import hashlib
4
4
  import os
5
5
  import re
6
6
  import time
7
- import typing
8
7
  from base64 import b64encode
8
+ from collections.abc import AsyncGenerator, Callable, Generator
9
+ from typing import TYPE_CHECKING, ClassVar, NamedTuple
9
10
  from urllib.request import parse_http_list
10
11
 
11
12
  from ._exceptions import ProtocolError
12
13
  from ._models import Cookies, Request, Response
13
14
  from ._utils import to_bytes, to_str
14
15
 
15
- if typing.TYPE_CHECKING:
16
- from collections.abc import Callable
16
+ if TYPE_CHECKING:
17
17
  from hashlib import _Hash
18
18
 
19
19
  __all__ = ["Auth", "BasicAuth", "DigestAuth", "FunctionAuth", "NetRCAuth"]
@@ -35,7 +35,7 @@ class Auth:
35
35
  requires_request_body = False
36
36
  requires_response_body = False
37
37
 
38
- def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:
38
+ def auth_flow(self, request: Request) -> Generator[Request, Response, None]:
39
39
  """
40
40
  Execute the authentication flow.
41
41
 
@@ -59,7 +59,7 @@ class Auth:
59
59
  """
60
60
  yield request
61
61
 
62
- def sync_auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:
62
+ def sync_auth_flow(self, request: Request) -> Generator[Request, Response, None]:
63
63
  """
64
64
  Execute the authentication flow synchronously.
65
65
 
@@ -82,7 +82,7 @@ class Auth:
82
82
  except StopIteration:
83
83
  break
84
84
 
85
- async def async_auth_flow(self, request: Request) -> typing.AsyncGenerator[Request, Response]:
85
+ async def async_auth_flow(self, request: Request) -> AsyncGenerator[Request, Response]:
86
86
  """
87
87
  Execute the authentication flow asynchronously.
88
88
 
@@ -112,10 +112,10 @@ class FunctionAuth(Auth):
112
112
  that takes the request, and returns a new, modified request.
113
113
  """
114
114
 
115
- def __init__(self, func: typing.Callable[[Request], Request]) -> None:
115
+ def __init__(self, func: Callable[[Request], Request]) -> None:
116
116
  self._func = func
117
117
 
118
- def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:
118
+ def auth_flow(self, request: Request) -> Generator[Request, Response, None]:
119
119
  yield self._func(request)
120
120
 
121
121
 
@@ -128,7 +128,7 @@ class BasicAuth(Auth):
128
128
  def __init__(self, username: str | bytes, password: str | bytes) -> None:
129
129
  self._auth_header = self._build_auth_header(username, password)
130
130
 
131
- def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:
131
+ def auth_flow(self, request: Request) -> Generator[Request, Response, None]:
132
132
  request.headers["Authorization"] = self._auth_header
133
133
  yield request
134
134
 
@@ -150,7 +150,7 @@ class NetRCAuth(Auth):
150
150
 
151
151
  self._netrc_info = netrc.netrc(file)
152
152
 
153
- def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:
153
+ def auth_flow(self, request: Request) -> Generator[Request, Response, None]:
154
154
  auth_info = self._netrc_info.authenticators(request.url.host)
155
155
  if auth_info is None or not auth_info[2]:
156
156
  # The netrc file did not have authentication credentials for this host.
@@ -168,7 +168,7 @@ class NetRCAuth(Auth):
168
168
 
169
169
  class DigestAuth(Auth):
170
170
  # Hashes are resolved by name at use time, since FIPS builds may remove or block MD5.
171
- _ALGORITHM_TO_HASH_NAME = {
171
+ _ALGORITHM_TO_HASH_NAME: ClassVar[dict[str, str]] = {
172
172
  "MD5": "md5",
173
173
  "MD5-SESS": "md5",
174
174
  "SHA": "sha1",
@@ -185,7 +185,7 @@ class DigestAuth(Auth):
185
185
  self._last_challenge: _DigestAuthChallenge | None = None
186
186
  self._nonce_count = 1
187
187
 
188
- def auth_flow(self, request: Request) -> typing.Generator[Request, Response, None]:
188
+ def auth_flow(self, request: Request) -> Generator[Request, Response, None]:
189
189
  if self._last_challenge:
190
190
  request.headers["Authorization"] = self._build_auth_header(request, self._last_challenge)
191
191
 
@@ -226,7 +226,7 @@ class DigestAuth(Auth):
226
226
  header_dict: dict[str, str] = {}
227
227
  for field in parse_http_list(fields):
228
228
  key, value = field.strip().split("=", 1)
229
- header_dict[key] = value.strip('"')
229
+ header_dict[key.strip().lower()] = value.strip().strip('"')
230
230
 
231
231
  try:
232
232
  realm = header_dict["realm"].encode()
@@ -327,7 +327,7 @@ class DigestAuth(Auth):
327
327
  raise ProtocolError(message, request=request)
328
328
 
329
329
 
330
- class _DigestAuthChallenge(typing.NamedTuple):
330
+ class _DigestAuthChallenge(NamedTuple):
331
331
  realm: bytes
332
332
  nonce: bytes
333
333
  algorithm: str