httpx2 2.10.0__tar.gz → 2.11.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.
Files changed (37) hide show
  1. {httpx2-2.10.0 → httpx2-2.11.0}/CHANGELOG.md +20 -0
  2. {httpx2-2.10.0 → httpx2-2.11.0}/PKG-INFO +16 -17
  3. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/__init__.py +1 -0
  4. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_client.py +8 -20
  5. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_models.py +4 -1
  6. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_multipart.py +6 -0
  7. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_status_codes.py +10 -5
  8. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_transports/wsgi.py +2 -0
  9. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_urls.py +58 -1
  10. {httpx2-2.10.0 → httpx2-2.11.0}/pyproject.toml +3 -3
  11. {httpx2-2.10.0 → httpx2-2.11.0}/.gitignore +0 -0
  12. {httpx2-2.10.0 → httpx2-2.11.0}/LICENSE.md +0 -0
  13. {httpx2-2.10.0 → httpx2-2.11.0}/README.md +0 -0
  14. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/__version__.py +0 -0
  15. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_alias.py +0 -0
  16. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_api.py +0 -0
  17. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_auth.py +0 -0
  18. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_config.py +0 -0
  19. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_content.py +0 -0
  20. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_decoders.py +0 -0
  21. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_exceptions.py +0 -0
  22. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_main.py +0 -0
  23. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_sse.py +0 -0
  24. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_transports/__init__.py +0 -0
  25. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_transports/asgi.py +0 -0
  26. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_transports/base.py +0 -0
  27. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_transports/default.py +0 -0
  28. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_transports/mock.py +0 -0
  29. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_types.py +0 -0
  30. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_urlparse.py +0 -0
  31. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/_utils.py +0 -0
  32. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/py.typed +0 -0
  33. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/websockets/__init__.py +0 -0
  34. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/websockets/_api.py +0 -0
  35. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/websockets/_exceptions.py +0 -0
  36. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/websockets/_ping.py +0 -0
  37. {httpx2-2.10.0 → httpx2-2.11.0}/httpx2/websockets/_transport.py +0 -0
@@ -4,6 +4,26 @@ 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.11.0 (August 18th, 2026)
8
+
9
+ ### Added
10
+
11
+ * Add the public `Origin` value object and `URL.origin` property for normalized,
12
+ hashable origin comparisons. ([#1134](https://github.com/pydantic/httpx2/pull/1134))
13
+
14
+ ### Changed
15
+
16
+ * Require Brotli 1.2.0 or later for the `brotli` extra. ([#1141](https://github.com/pydantic/httpx2/pull/1141))
17
+
18
+ ### Fixed
19
+
20
+ * Restore deprecated status code aliases. ([#1135](https://github.com/pydantic/httpx2/pull/1135))
21
+ * Extract HTTP/2 release notes from changelog headings correctly. ([#1136](https://github.com/pydantic/httpx2/pull/1136))
22
+ * Respect explicit `Transfer-Encoding` headers and expose buffered request body lengths to WSGI applications.
23
+ ([#1137](https://github.com/pydantic/httpx2/pull/1137))
24
+ * Validate multipart part header names and values before serialization.
25
+ ([#1142](https://github.com/pydantic/httpx2/pull/1142))
26
+
7
27
  ## 2.10.0 (August 9th, 2026)
8
28
 
9
29
  ### Added
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.4
1
+ Metadata-Version: 2.5
2
2
  Name: httpx2
3
- Version: 2.10.0
3
+ Version: 2.11.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
@@ -27,14 +27,14 @@ Classifier: Programming Language :: Python :: 3.15
27
27
  Classifier: Topic :: Internet :: WWW/HTTP
28
28
  Requires-Python: >=3.10
29
29
  Requires-Dist: anyio>=4.10; sys_platform != 'emscripten'
30
- Requires-Dist: httpcore2==2.10.0; sys_platform != 'emscripten'
30
+ Requires-Dist: httpcore2==2.11.0; sys_platform != 'emscripten'
31
31
  Requires-Dist: httpx2-jsfetch; sys_platform == 'emscripten' and python_version >= '3.12'
32
32
  Requires-Dist: idna>=3.18
33
33
  Requires-Dist: truststore>=0.10; sys_platform != 'emscripten'
34
34
  Requires-Dist: typing-extensions>=4.5.0; python_version < '3.13'
35
35
  Provides-Extra: brotli
36
- Requires-Dist: brotli; (platform_python_implementation == 'CPython') and extra == 'brotli'
37
- Requires-Dist: brotlicffi; (platform_python_implementation != 'CPython') and extra == 'brotli'
36
+ Requires-Dist: brotli>=1.2.0; (platform_python_implementation == 'CPython') and extra == 'brotli'
37
+ Requires-Dist: brotlicffi>=1.2.0.0; (platform_python_implementation != 'CPython') and extra == 'brotli'
38
38
  Provides-Extra: cli
39
39
  Requires-Dist: click>=8.4.2; extra == 'cli'
40
40
  Requires-Dist: pygments==2.*; extra == 'cli'
@@ -212,26 +212,25 @@ inspiration around the lower-level networking details.
212
212
 
213
213
  ## Release Information
214
214
 
215
+ ## 2.11.0 (August 18th, 2026)
216
+
215
217
  ### Added
216
218
 
217
- * Add support for running on WebAssembly / Emscripten via Pyodide, using a JavaScript
218
- `fetch`-based transport defined in `httpx2-jsfetch`.
219
- ([#1119](https://github.com/pydantic/httpx2/pull/1119))
220
- * Add `max_event_size` to cap SSE event buffering. ([#1071](https://github.com/pydantic/httpx2/pull/1071))
221
- * Add RFC 9110 status code constants. ([#1069](https://github.com/pydantic/httpx2/pull/1069))
222
- * Add support for Python 3.15. ([#1090](https://github.com/pydantic/httpx2/pull/1090))
219
+ * Add the public `Origin` value object and `URL.origin` property for normalized,
220
+ hashable origin comparisons. ([#1134](https://github.com/pydantic/httpx2/pull/1134))
223
221
 
224
222
  ### Changed
225
223
 
226
- * Improve SSE chunk buffering performance. ([#1117](https://github.com/pydantic/httpx2/pull/1117))
227
- * Skip cookie extraction for responses without `Set-Cookie` headers. ([#1107](https://github.com/pydantic/httpx2/pull/1107))
228
- * Return `str | None` instead of `Any` from `Headers.get`. ([#1121](https://github.com/pydantic/httpx2/pull/1121))
224
+ * Require Brotli 1.2.0 or later for the `brotli` extra. ([#1141](https://github.com/pydantic/httpx2/pull/1141))
229
225
 
230
226
  ### Fixed
231
227
 
232
- * Enforce the WebSocket max message size across fragmented messages. ([#1085](https://github.com/pydantic/httpx2/pull/1085))
233
- * Ignore unsolicited and duplicate WebSocket Pong frames. ([#1122](https://github.com/pydantic/httpx2/pull/1122))
234
-
228
+ * Restore deprecated status code aliases. ([#1135](https://github.com/pydantic/httpx2/pull/1135))
229
+ * Extract HTTP/2 release notes from changelog headings correctly. ([#1136](https://github.com/pydantic/httpx2/pull/1136))
230
+ * Respect explicit `Transfer-Encoding` headers and expose buffered request body lengths to WSGI applications.
231
+ ([#1137](https://github.com/pydantic/httpx2/pull/1137))
232
+ * Validate multipart part header names and values before serialization.
233
+ ([#1142](https://github.com/pydantic/httpx2/pull/1142))
235
234
 
236
235
  ---
237
236
 
@@ -53,6 +53,7 @@ __all__ = [
53
53
  "NetRCAuth",
54
54
  "NetworkError",
55
55
  "options",
56
+ "Origin",
56
57
  "patch",
57
58
  "PoolTimeout",
58
59
  "post",
@@ -72,30 +72,18 @@ def _is_https_redirect(url: URL, location: URL) -> bool:
72
72
  """
73
73
  Return 'True' if 'location' is a HTTPS upgrade of 'url'
74
74
  """
75
- if url.host != location.host:
76
- return False
75
+ origin = url.origin
76
+ location_origin = location.origin
77
77
 
78
78
  return (
79
- url.scheme == "http"
80
- and _port_or_default(url) == 80
81
- and location.scheme == "https"
82
- and _port_or_default(location) == 443
79
+ origin.host == location_origin.host
80
+ and origin.scheme == "http"
81
+ and origin.port == 80
82
+ and location_origin.scheme == "https"
83
+ and location_origin.port == 443
83
84
  )
84
85
 
85
86
 
86
- def _port_or_default(url: URL) -> int | None:
87
- if url.port is not None:
88
- return url.port
89
- return {"http": 80, "https": 443}.get(url.scheme)
90
-
91
-
92
- def _same_origin(url: URL, other: URL) -> bool:
93
- """
94
- Return 'True' if the given URLs share the same origin.
95
- """
96
- return url.scheme == other.scheme and url.host == other.host and _port_or_default(url) == _port_or_default(other)
97
-
98
-
99
87
  class UseClientDefault:
100
88
  """
101
89
  For some parameters such as `auth=...` and `timeout=...` we need to be able
@@ -534,7 +522,7 @@ class BaseClient:
534
522
  """
535
523
  headers = Headers(request.headers)
536
524
 
537
- if not _same_origin(url, request.url):
525
+ if url.origin != request.url.origin:
538
526
  if not _is_https_redirect(request.url, url):
539
527
  # Strip Authorization headers when responses are redirected
540
528
  # away from the origin. (Except for direct HTTP to HTTPS redirects.)
@@ -452,7 +452,10 @@ class Request:
452
452
 
453
453
  def _prepare(self, default_headers: dict[str, str]) -> None:
454
454
  for key, value in default_headers.items():
455
- # Ignore Transfer-Encoding if the Content-Length has been set explicitly.
455
+ # Ignore Content-Length if Transfer-Encoding has been set explicitly.
456
+ if key.lower() == "content-length" and "Transfer-Encoding" in self.headers:
457
+ continue
458
+ # Ignore Transfer-Encoding if Content-Length has been set explicitly.
456
459
  if key.lower() == "transfer-encoding" and "Content-Length" in self.headers:
457
460
  continue
458
461
  self.headers.setdefault(key, value)
@@ -24,6 +24,8 @@ from ._utils import (
24
24
  _HTML5_FORM_ENCODING_REPLACEMENTS = {'"': "%22", "\\": "\\\\"}
25
25
  _HTML5_FORM_ENCODING_REPLACEMENTS.update({chr(c): f"%{c:02X}" for c in range(0x1F + 1) if c != 0x1B})
26
26
  _HTML5_FORM_ENCODING_RE = re.compile(r"|".join([re.escape(c) for c in _HTML5_FORM_ENCODING_REPLACEMENTS.keys()]))
27
+ _HEADER_NAME_RE = re.compile(r"[!#$%&'*+\-.^_`|~0-9A-Za-z]+")
28
+ _FORBIDDEN_HEADER_VALUE_CHARS_RE = re.compile(r"[\x00-\x08\x0a-\x1f\x7f]")
27
29
 
28
30
 
29
31
  def _format_form_param(name: str, value: str) -> bytes:
@@ -176,6 +178,10 @@ class FileField:
176
178
  filename = _format_form_param("filename", self.filename)
177
179
  parts.extend([b"; ", filename])
178
180
  for header_name, header_value in self.headers.items():
181
+ if _HEADER_NAME_RE.fullmatch(header_name) is None:
182
+ raise ValueError("Invalid multipart header name.")
183
+ if _FORBIDDEN_HEADER_VALUE_CHARS_RE.search(header_value) is not None:
184
+ raise ValueError("Invalid control character in multipart header value.")
179
185
  key, val = f"\r\n{header_name}: ".encode(), header_value.encode()
180
186
  parts.extend([key, val])
181
187
  parts.append(b"\r\n\r\n")
@@ -16,7 +16,7 @@ _DEPRECATED_CODES = {
16
16
 
17
17
 
18
18
  class _CodesMeta(EnumMeta):
19
- def __getattr__(cls, name: str) -> codes:
19
+ def __getattribute__(cls, name: str) -> object:
20
20
  if name in _DEPRECATED_CODES:
21
21
  new_name = _DEPRECATED_CODES[name]
22
22
  warnings.warn(
@@ -24,8 +24,7 @@ class _CodesMeta(EnumMeta):
24
24
  category=DeprecationWarning,
25
25
  stacklevel=2,
26
26
  )
27
- return cls[new_name]
28
- raise AttributeError(name)
27
+ return super().__getattribute__(name)
29
28
 
30
29
 
31
30
  class codes(IntEnum, metaclass=_CodesMeta):
@@ -178,7 +177,13 @@ class codes(IntEnum, metaclass=_CodesMeta):
178
177
  NOT_EXTENDED = 510, "Not Extended"
179
178
  NETWORK_AUTHENTICATION_REQUIRED = 511, "Network Authentication Required"
180
179
 
180
+ # Deprecated aliases for names replaced by RFC 9110.
181
+ REQUEST_ENTITY_TOO_LARGE = CONTENT_TOO_LARGE
182
+ REQUEST_URI_TOO_LONG = URI_TOO_LONG
183
+ REQUESTED_RANGE_NOT_SATISFIABLE = RANGE_NOT_SATISFIABLE
184
+ UNPROCESSABLE_ENTITY = UNPROCESSABLE_CONTENT
185
+
181
186
 
182
187
  # Include lower-case styles for `requests` compatibility.
183
- for code in codes:
184
- setattr(codes, code._name_.lower(), int(code))
188
+ for name, code in codes.__members__.items():
189
+ setattr(codes, name.lower(), int(code))
@@ -107,6 +107,8 @@ class WSGITransport(BaseTransport):
107
107
  "SERVER_PROTOCOL": "HTTP/1.1",
108
108
  "REMOTE_ADDR": self.remote_addr,
109
109
  }
110
+ if request.content and "Content-Length" not in request.headers:
111
+ environ["CONTENT_LENGTH"] = str(len(request.content))
110
112
  for header_key, header_value in request.headers.raw:
111
113
  key = header_key.decode("ascii").upper().replace("-", "_")
112
114
  if key not in ("CONTENT_TYPE", "CONTENT_LENGTH"):
@@ -1,7 +1,9 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import ipaddress
3
4
  import sys
4
5
  import typing
6
+ from dataclasses import dataclass
5
7
  from urllib.parse import parse_qs, unquote, urlencode
6
8
 
7
9
  import idna
@@ -16,7 +18,7 @@ from ._types import QueryParamTypes
16
18
  from ._urlparse import urlparse
17
19
  from ._utils import primitive_value_to_str
18
20
 
19
- __all__ = ["URL", "QueryParams"]
21
+ __all__ = ["URL", "Origin", "QueryParams"]
20
22
 
21
23
 
22
24
  class URL:
@@ -328,6 +330,16 @@ class URL:
328
330
  """
329
331
  return not self.is_absolute_url
330
332
 
333
+ @property
334
+ def origin(self) -> Origin:
335
+ """
336
+ The URL origin as an immutable, hashable `Origin` value.
337
+
338
+ The origin consists of the URL scheme, host, and effective port.
339
+ User information, path, query, and fragment components are excluded.
340
+ """
341
+ return Origin(self)
342
+
331
343
  def copy_with(self, **kwargs: typing.Any) -> URL:
332
344
  """
333
345
  Copy this URL, returning a new URL with some components altered.
@@ -418,6 +430,51 @@ class URL:
418
430
  )
419
431
 
420
432
 
433
+ _ORIGIN_DEFAULT_PORTS = {
434
+ "ftp": 21,
435
+ "http": 80,
436
+ "https": 443,
437
+ "ws": 80,
438
+ "wss": 443,
439
+ }
440
+
441
+
442
+ @dataclass(frozen=True, slots=True, init=False)
443
+ class Origin:
444
+ """
445
+ The scheme, host, and effective port of a URL.
446
+
447
+ Origins are normalized, immutable, comparable, and hashable.
448
+
449
+ See RFC 9110, Section 4.3.1: https://www.rfc-editor.org/rfc/rfc9110.html#name-uri-origin
450
+ """
451
+
452
+ scheme: str
453
+ host: str
454
+ port: int | None
455
+
456
+ def __init__(self, url: URL | str) -> None:
457
+ if not isinstance(url, URL):
458
+ url = URL(url)
459
+
460
+ if url.is_relative_url:
461
+ raise ValueError("URL must be absolute to have an origin")
462
+
463
+ host = url.host
464
+ if b":" in url.raw_host:
465
+ # IPv6 addresses may have multiple equivalent string forms. Store
466
+ # their canonical compressed form so origin equality is numeric.
467
+ host = str(ipaddress.IPv6Address(url.raw_host.decode("ascii")))
468
+
469
+ port = url.port
470
+ if port is None:
471
+ port = _ORIGIN_DEFAULT_PORTS.get(url.scheme)
472
+
473
+ object.__setattr__(self, "scheme", url.scheme)
474
+ object.__setattr__(self, "host", host)
475
+ object.__setattr__(self, "port", port)
476
+
477
+
421
478
  class QueryParams(typing.Mapping[str, str]):
422
479
  """
423
480
  URL query parameters, as a multi-dict.
@@ -55,8 +55,8 @@ dependencies = [
55
55
 
56
56
  [project.optional-dependencies]
57
57
  brotli = [
58
- "brotli; platform_python_implementation == 'CPython'",
59
- "brotlicffi; platform_python_implementation != 'CPython'",
58
+ "brotli>=1.2.0; platform_python_implementation == 'CPython'",
59
+ "brotlicffi>=1.2.0.0; platform_python_implementation != 'CPython'",
60
60
  ]
61
61
  cli = [
62
62
  "click>=8.4.2",
@@ -106,7 +106,7 @@ text = "\n## Release Information\n\n"
106
106
 
107
107
  [[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
108
108
  path = "CHANGELOG.md"
109
- pattern = "\n(###.+?\n)## "
109
+ pattern = "\n(## [0-9].+?)(?=\n## |$)"
110
110
 
111
111
  [[tool.hatch.metadata.hooks.fancy-pypi-readme.fragments]]
112
112
  text = "\n---\n\n[Full changelog](https://github.com/pydantic/httpx2/blob/main/src/httpx2/CHANGELOG.md)\n"
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