httpx2 2.15.0__tar.gz → 2.16.0__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.
- {httpx2-2.15.0 → httpx2-2.16.0}/CHANGELOG.md +19 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/PKG-INFO +11 -5
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_client.py +7 -8
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_config.py +2 -8
- httpx2-2.16.0/httpx2/_cookies.py +74 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_models.py +5 -4
- {httpx2-2.15.0 → httpx2-2.16.0}/.gitignore +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/LICENSE.md +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/README.md +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/__init__.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/__version__.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_alias.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_api.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_auth.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_content.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_decoders.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_exceptions.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_main.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_multipart.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_sse.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_status_codes.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_transports/__init__.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_transports/asgi.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_transports/base.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_transports/default.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_transports/mock.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_transports/wsgi.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_types.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_urlparse.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_urls.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/_utils.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/py.typed +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/websockets/__init__.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/websockets/_api.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/websockets/_exceptions.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/websockets/_ping.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/httpx2/websockets/_transport.py +0 -0
- {httpx2-2.15.0 → httpx2-2.16.0}/pyproject.toml +0 -0
|
@@ -4,6 +4,25 @@ 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.0 (October 21st, 2026)
|
|
8
|
+
|
|
9
|
+
### Changed
|
|
10
|
+
|
|
11
|
+
* 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.
|
|
12
|
+
([#1285](https://github.com/pydantic/httpx2/pull/1285))
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
* 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.
|
|
17
|
+
([#1284](https://github.com/pydantic/httpx2/pull/1284))
|
|
18
|
+
|
|
19
|
+
## 2.15.1 (October 19th, 2026)
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
* 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.
|
|
24
|
+
([#1253](https://github.com/pydantic/httpx2/pull/1253))
|
|
25
|
+
|
|
7
26
|
## 2.15.0 (October 19th, 2026)
|
|
8
27
|
|
|
9
28
|
### Removed
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: httpx2
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.16.0
|
|
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.
|
|
29
|
+
Requires-Dist: httpcore2==2.16.0; 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'
|
|
@@ -212,11 +212,17 @@ inspiration around the lower-level networking details.
|
|
|
212
212
|
|
|
213
213
|
## Release Information
|
|
214
214
|
|
|
215
|
-
## 2.
|
|
215
|
+
## 2.16.0 (October 21st, 2026)
|
|
216
216
|
|
|
217
|
-
###
|
|
217
|
+
### Changed
|
|
218
218
|
|
|
219
|
-
*
|
|
219
|
+
* 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.
|
|
220
|
+
([#1285](https://github.com/pydantic/httpx2/pull/1285))
|
|
221
|
+
|
|
222
|
+
### Fixed
|
|
223
|
+
|
|
224
|
+
* 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.
|
|
225
|
+
([#1284](https://github.com/pydantic/httpx2/pull/1284))
|
|
220
226
|
|
|
221
227
|
---
|
|
222
228
|
|
|
@@ -392,16 +392,16 @@ class BaseClient:
|
|
|
392
392
|
return self.base_url.copy_with(raw_path=merge_raw_path)
|
|
393
393
|
return merge_url
|
|
394
394
|
|
|
395
|
-
def _merge_cookies(self, cookies: CookieTypes | None = None) ->
|
|
395
|
+
def _merge_cookies(self, cookies: CookieTypes | None = None) -> Cookies:
|
|
396
396
|
"""
|
|
397
397
|
Merge a cookies argument together with any cookies on the client,
|
|
398
398
|
to create the cookies used for the outgoing request.
|
|
399
399
|
"""
|
|
400
|
-
if
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
return
|
|
400
|
+
if not cookies:
|
|
401
|
+
return self.cookies
|
|
402
|
+
merged_cookies = Cookies(self.cookies)
|
|
403
|
+
merged_cookies.update(cookies)
|
|
404
|
+
return merged_cookies
|
|
405
405
|
|
|
406
406
|
def _merge_headers(self, headers: HeaderTypes | None = None) -> HeaderTypes | None:
|
|
407
407
|
"""
|
|
@@ -459,12 +459,11 @@ class BaseClient:
|
|
|
459
459
|
url = self._redirect_url(request, response)
|
|
460
460
|
headers = self._redirect_headers(request, url, method)
|
|
461
461
|
stream = self._redirect_stream(request, method)
|
|
462
|
-
cookies = Cookies(self.cookies)
|
|
463
462
|
return Request(
|
|
464
463
|
method=method,
|
|
465
464
|
url=url,
|
|
466
465
|
headers=headers,
|
|
467
|
-
cookies=cookies,
|
|
466
|
+
cookies=self.cookies,
|
|
468
467
|
stream=stream,
|
|
469
468
|
extensions=request.extensions,
|
|
470
469
|
)
|
|
@@ -29,16 +29,10 @@ def create_ssl_context(
|
|
|
29
29
|
import ssl
|
|
30
30
|
import warnings
|
|
31
31
|
|
|
32
|
-
import
|
|
32
|
+
import httpcore2
|
|
33
33
|
|
|
34
34
|
if verify is True:
|
|
35
|
-
|
|
36
|
-
ctx = ssl.create_default_context(cafile=os.environ["SSL_CERT_FILE"])
|
|
37
|
-
elif trust_env and os.environ.get("SSL_CERT_DIR"): # pragma: no cover
|
|
38
|
-
ctx = ssl.create_default_context(capath=os.environ["SSL_CERT_DIR"])
|
|
39
|
-
else:
|
|
40
|
-
# Default case: rely on the system trust store via `truststore`.
|
|
41
|
-
ctx = truststore.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
35
|
+
ctx = httpcore2.default_ssl_context(_trust_env=trust_env)
|
|
42
36
|
elif verify is False:
|
|
43
37
|
ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
|
|
44
38
|
ctx.check_hostname = False
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import threading
|
|
3
|
+
import time
|
|
4
|
+
import urllib.request
|
|
5
|
+
from http import cookiejar
|
|
6
|
+
from http.cookiejar import Cookie, CookieJar, CookiePolicy, DefaultCookiePolicy
|
|
7
|
+
from typing import TYPE_CHECKING
|
|
8
|
+
|
|
9
|
+
__all__ = ["IndexedCookieJar"]
|
|
10
|
+
|
|
11
|
+
# [RFC 1035](https://www.rfc-editor.org/rfc/rfc1035#section-2.3.4) caps DNS names at 255 octets;
|
|
12
|
+
# longer hosts fall back to scanning every stored domain.
|
|
13
|
+
MAX_HOST_LENGTH = 255
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class IndexedCookieJar(CookieJar):
|
|
17
|
+
"""
|
|
18
|
+
A `CookieJar` whose per-request cost does not grow with the number of stored cookies.
|
|
19
|
+
|
|
20
|
+
Compared to `CookieJar`, on each request it:
|
|
21
|
+
|
|
22
|
+
1. Looks up only the domains that can match the request host, instead of checking every stored domain.
|
|
23
|
+
2. Skips the expiry sweep until the earliest known expiry has passed, instead of checking every stored cookie.
|
|
24
|
+
"""
|
|
25
|
+
|
|
26
|
+
_cookies: dict[str, dict[str, dict[str, Cookie]]]
|
|
27
|
+
_cookies_lock: threading.RLock
|
|
28
|
+
_policy: CookiePolicy
|
|
29
|
+
_next_expiry: float = math.inf
|
|
30
|
+
|
|
31
|
+
if TYPE_CHECKING:
|
|
32
|
+
|
|
33
|
+
def _cookies_for_domain(self, domain: str, request: urllib.request.Request) -> list[Cookie]: ...
|
|
34
|
+
|
|
35
|
+
def set_cookie(self, cookie: Cookie) -> None:
|
|
36
|
+
with self._cookies_lock:
|
|
37
|
+
super().set_cookie(cookie)
|
|
38
|
+
if cookie.expires is not None:
|
|
39
|
+
self._next_expiry = min(self._next_expiry, cookie.expires)
|
|
40
|
+
|
|
41
|
+
def clear_expired_cookies(self) -> None:
|
|
42
|
+
if time.time() < self._next_expiry:
|
|
43
|
+
return
|
|
44
|
+
with self._cookies_lock:
|
|
45
|
+
super().clear_expired_cookies()
|
|
46
|
+
self._next_expiry = min((c.expires for c in self if c.expires is not None), default=math.inf)
|
|
47
|
+
|
|
48
|
+
def _cookies_for_request(self, request: urllib.request.Request) -> list[Cookie]:
|
|
49
|
+
hosts: tuple[str, str] = cookiejar.eff_request_host(request) # type: ignore[attr-defined]
|
|
50
|
+
uses_default_matching = type(self._policy).domain_return_ok is DefaultCookiePolicy.domain_return_ok
|
|
51
|
+
if not uses_default_matching or max(map(len, hosts)) > MAX_HOST_LENGTH:
|
|
52
|
+
return super()._cookies_for_request(request) # type: ignore[misc, no-any-return]
|
|
53
|
+
|
|
54
|
+
cookies: list[Cookie] = []
|
|
55
|
+
for domain in _matching_domains(hosts):
|
|
56
|
+
if domain in self._cookies:
|
|
57
|
+
cookies.extend(self._cookies_for_domain(domain, request))
|
|
58
|
+
return cookies
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def _matching_domains(hosts: tuple[str, str]) -> dict[str, None]:
|
|
62
|
+
"""
|
|
63
|
+
Every cookie domain `DefaultCookiePolicy.domain_return_ok` can accept for these hosts, least specific first.
|
|
64
|
+
|
|
65
|
+
For `a.example.org` that is `""`, `.org`, `org`, `.example.org`, `example.org`, `.a.example.org`, `a.example.org`.
|
|
66
|
+
"""
|
|
67
|
+
domains = {"": None}
|
|
68
|
+
for host in hosts:
|
|
69
|
+
dotted = host if host.startswith(".") else f".{host}"
|
|
70
|
+
for index in range(len(dotted) - 1, -1, -1):
|
|
71
|
+
if dotted[index] == ".":
|
|
72
|
+
domains[dotted[index:]] = None
|
|
73
|
+
domains[dotted[index + 1 :]] = None
|
|
74
|
+
return domains
|
|
@@ -12,6 +12,7 @@ from collections.abc import AsyncGenerator, Mapping
|
|
|
12
12
|
from http.cookiejar import Cookie, CookieJar
|
|
13
13
|
|
|
14
14
|
from ._content import ByteStream, UnattachedStream, encode_request, encode_response
|
|
15
|
+
from ._cookies import IndexedCookieJar
|
|
15
16
|
from ._decoders import (
|
|
16
17
|
ByteChunker,
|
|
17
18
|
ContentDecoder,
|
|
@@ -416,7 +417,7 @@ class Request:
|
|
|
416
417
|
self.extensions = {} if extensions is None else dict(extensions)
|
|
417
418
|
|
|
418
419
|
if cookies:
|
|
419
|
-
Cookies(cookies).set_cookie_header(self)
|
|
420
|
+
(cookies if isinstance(cookies, Cookies) else Cookies(cookies)).set_cookie_header(self)
|
|
420
421
|
|
|
421
422
|
if stream is None:
|
|
422
423
|
content_type: str | None = self.headers.get("content-type")
|
|
@@ -1079,16 +1080,16 @@ class Cookies(typing.MutableMapping[str, str]):
|
|
|
1079
1080
|
|
|
1080
1081
|
def __init__(self, cookies: CookieTypes | None = None) -> None:
|
|
1081
1082
|
if cookies is None or isinstance(cookies, dict):
|
|
1082
|
-
self.jar =
|
|
1083
|
+
self.jar: CookieJar = IndexedCookieJar()
|
|
1083
1084
|
if isinstance(cookies, dict):
|
|
1084
1085
|
for key, value in cookies.items():
|
|
1085
1086
|
self.set(key, value)
|
|
1086
1087
|
elif isinstance(cookies, list):
|
|
1087
|
-
self.jar =
|
|
1088
|
+
self.jar = IndexedCookieJar()
|
|
1088
1089
|
for key, value in cookies:
|
|
1089
1090
|
self.set(key, value)
|
|
1090
1091
|
elif isinstance(cookies, Cookies):
|
|
1091
|
-
self.jar =
|
|
1092
|
+
self.jar = IndexedCookieJar()
|
|
1092
1093
|
for cookie in cookies.jar:
|
|
1093
1094
|
self.jar.set_cookie(cookie)
|
|
1094
1095
|
else:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|