httpx2 2.12.0__tar.gz → 2.13.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 (37) hide show
  1. {httpx2-2.12.0 → httpx2-2.13.1}/CHANGELOG.md +24 -0
  2. {httpx2-2.12.0 → httpx2-2.13.1}/PKG-INFO +19 -21
  3. {httpx2-2.12.0 → httpx2-2.13.1}/README.md +11 -10
  4. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/__init__.py +54 -40
  5. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_api.py +1 -1
  6. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_client.py +8 -8
  7. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_config.py +6 -35
  8. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_content.py +2 -2
  9. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_main.py +3 -5
  10. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_urls.py +1 -1
  11. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_utils.py +12 -0
  12. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/websockets/_api.py +4 -1
  13. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/websockets/_exceptions.py +1 -1
  14. {httpx2-2.12.0 → httpx2-2.13.1}/pyproject.toml +2 -2
  15. {httpx2-2.12.0 → httpx2-2.13.1}/.gitignore +0 -0
  16. {httpx2-2.12.0 → httpx2-2.13.1}/LICENSE.md +0 -0
  17. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/__version__.py +0 -0
  18. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_alias.py +0 -0
  19. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_auth.py +0 -0
  20. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_decoders.py +0 -0
  21. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_exceptions.py +0 -0
  22. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_models.py +0 -0
  23. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_multipart.py +0 -0
  24. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_sse.py +0 -0
  25. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_status_codes.py +0 -0
  26. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_transports/__init__.py +0 -0
  27. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_transports/asgi.py +0 -0
  28. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_transports/base.py +0 -0
  29. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_transports/default.py +0 -0
  30. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_transports/mock.py +0 -0
  31. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_transports/wsgi.py +0 -0
  32. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_types.py +0 -0
  33. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/_urlparse.py +0 -0
  34. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/py.typed +0 -0
  35. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/websockets/__init__.py +0 -0
  36. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/websockets/_ping.py +0 -0
  37. {httpx2-2.12.0 → httpx2-2.13.1}/httpx2/websockets/_transport.py +0 -0
@@ -4,6 +4,30 @@ 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.13.1 (September 23rd, 2026)
8
+
9
+ ### Fixed
10
+
11
+ * Calculate `Content-Length` from the remaining bytes when a file is passed as `content=`, respecting its current position.
12
+ ([#1214](https://github.com/pydantic/httpx2/pull/1214))
13
+ * Stop the sync WebSocket keepalive thread cleanly when a ping races with connection shutdown.
14
+ ([#1228](https://github.com/pydantic/httpx2/pull/1228))
15
+
16
+ ## 2.13.0 (September 14th, 2026)
17
+
18
+ ### Changed
19
+
20
+ * Require `brotlicffi` 1.2.0.2 or later for the `brotli` extra on non-CPython implementations.
21
+ ([#1179](https://github.com/pydantic/httpx2/pull/1179))
22
+
23
+ ### Fixed
24
+
25
+ * Make the `--no-verify` CLI flag disable TLS certificate verification and add an explicit `--verify` counterpart.
26
+ ([#1140](https://github.com/pydantic/httpx2/pull/1140),
27
+ [#1186](https://github.com/pydantic/httpx2/pull/1186))
28
+ * Avoid nested async generator finalization errors when streamed responses are abandoned early.
29
+ ([#1204](https://github.com/pydantic/httpx2/pull/1204))
30
+
7
31
  ## 2.12.0 (August 18th, 2026)
8
32
 
9
33
  ### Changed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: httpx2
3
- Version: 2.12.0
3
+ Version: 2.13.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
@@ -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.12.0; sys_platform != 'emscripten'
30
+ Requires-Dist: httpcore2==2.13.1; 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
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'
37
+ Requires-Dist: brotlicffi>=1.2.0.2; (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'
@@ -56,6 +56,7 @@ Description-Content-Type: text/markdown
56
56
  <p align="center">
57
57
  <a href="https://github.com/pydantic/httpx2/actions"><img src="https://github.com/pydantic/httpx2/workflows/Test%20Suite/badge.svg" alt="Test Suite"></a>
58
58
  <a href="https://pypi.org/project/httpx2/"><img src="https://badge.fury.io/py/httpx2.svg" alt="Package version"></a>
59
+ <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
60
  </p>
60
61
 
61
62
  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**.
@@ -104,11 +105,11 @@ httpx2 --help
104
105
 
105
106
  HTTPX2 builds on the well-established usability of `requests`, and gives you:
106
107
 
107
- * A broadly [requests-compatible API](https://httpx2.pydantic.dev/compatibility/).
108
+ * A broadly [requests-compatible API](https://pydantic.dev/docs/httpx2/guides/compatibility/).
108
109
  * An integrated command-line client.
109
- * HTTP/1.1 [and HTTP/2 support](https://httpx2.pydantic.dev/http2/).
110
- * Standard synchronous interface, but with [async support if you need it](https://httpx2.pydantic.dev/async/).
111
- * Ability to make requests directly to [WSGI applications](https://httpx2.pydantic.dev/advanced/transports/#wsgi-transport) or [ASGI applications](https://httpx2.pydantic.dev/advanced/transports/#asgi-transport).
110
+ * HTTP/1.1 [and HTTP/2 support](https://pydantic.dev/docs/httpx2/guides/http2/).
111
+ * Standard synchronous interface, but with [async support if you need it](https://pydantic.dev/docs/httpx2/guides/async/).
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.
114
115
  * 100% test coverage.
@@ -147,15 +148,15 @@ pip install httpx2[http2]
147
148
 
148
149
  ## Documentation
149
150
 
150
- Project documentation is available at [https://httpx2.pydantic.dev/](https://httpx2.pydantic.dev/).
151
+ Project documentation is available at [https://pydantic.dev/docs/httpx2/](https://pydantic.dev/docs/httpx2/).
151
152
 
152
- For a run-through of all the basics, head over to the [QuickStart](https://httpx2.pydantic.dev/quickstart/).
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://httpx2.pydantic.dev/advanced/) section, the [async support](https://httpx2.pydantic.dev/async/) section, or the [HTTP/2](https://httpx2.pydantic.dev/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, or the [HTTP/2](https://pydantic.dev/docs/httpx2/guides/http2/) section.
155
156
 
156
- The [Developer Interface](https://httpx2.pydantic.dev/api/) provides a comprehensive API reference.
157
+ The [Developer Interface](https://pydantic.dev/docs/httpx2/api/api/) provides a comprehensive API reference.
157
158
 
158
- To find out about tools that integrate with HTTPX, see [Third Party Packages](https://httpx2.pydantic.dev/third_party_packages/).
159
+ To find out about tools that integrate with HTTPX, see [Third Party Packages](https://pydantic.dev/docs/httpx2/community/third_party_packages/).
159
160
 
160
161
  ## Observability with Pydantic Logfire
161
162
 
@@ -181,7 +182,7 @@ This works the same way for explicit `httpx2.Client()` and `httpx2.AsyncClient()
181
182
 
182
183
  ## Contribute
183
184
 
184
- If you want to contribute with HTTPX2 check out the [Contributing Guide](https://httpx2.pydantic.dev/contributing/) to learn how to start.
185
+ If you want to contribute with HTTPX2 check out the [Contributing Guide](https://pydantic.dev/docs/httpx2/community/contributing/) to learn how to start.
185
186
 
186
187
  ## Dependencies
187
188
 
@@ -212,17 +213,14 @@ inspiration around the lower-level networking details.
212
213
 
213
214
  ## Release Information
214
215
 
215
- ## 2.12.0 (August 18th, 2026)
216
-
217
- ### Changed
218
-
219
- * Use `backports.zstd` for Zstandard decoding on Python 3.13 and earlier.
220
- ([#1146](https://github.com/pydantic/httpx2/pull/1146))
216
+ ## 2.13.1 (September 23rd, 2026)
221
217
 
222
218
  ### Fixed
223
219
 
224
- * Bound peak memory while streaming compressed responses and close response streams when decoding fails.
225
- ([#1126](https://github.com/pydantic/httpx2/pull/1126))
220
+ * Calculate `Content-Length` from the remaining bytes when a file is passed as `content=`, respecting its current position.
221
+ ([#1214](https://github.com/pydantic/httpx2/pull/1214))
222
+ * Stop the sync WebSocket keepalive thread cleanly when a ping races with connection shutdown.
223
+ ([#1228](https://github.com/pydantic/httpx2/pull/1228))
226
224
 
227
225
  ---
228
226
 
@@ -5,6 +5,7 @@
5
5
  <p align="center">
6
6
  <a href="https://github.com/pydantic/httpx2/actions"><img src="https://github.com/pydantic/httpx2/workflows/Test%20Suite/badge.svg" alt="Test Suite"></a>
7
7
  <a href="https://pypi.org/project/httpx2/"><img src="https://badge.fury.io/py/httpx2.svg" alt="Package version"></a>
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>
8
9
  </p>
9
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**.
@@ -53,11 +54,11 @@ httpx2 --help
53
54
 
54
55
  HTTPX2 builds on the well-established usability of `requests`, and gives you:
55
56
 
56
- * A broadly [requests-compatible API](https://httpx2.pydantic.dev/compatibility/).
57
+ * A broadly [requests-compatible API](https://pydantic.dev/docs/httpx2/guides/compatibility/).
57
58
  * An integrated command-line client.
58
- * HTTP/1.1 [and HTTP/2 support](https://httpx2.pydantic.dev/http2/).
59
- * Standard synchronous interface, but with [async support if you need it](https://httpx2.pydantic.dev/async/).
60
- * Ability to make requests directly to [WSGI applications](https://httpx2.pydantic.dev/advanced/transports/#wsgi-transport) or [ASGI applications](https://httpx2.pydantic.dev/advanced/transports/#asgi-transport).
59
+ * HTTP/1.1 [and HTTP/2 support](https://pydantic.dev/docs/httpx2/guides/http2/).
60
+ * Standard synchronous interface, but with [async support if you need it](https://pydantic.dev/docs/httpx2/guides/async/).
61
+ * 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).
61
62
  * Strict timeouts everywhere.
62
63
  * Fully type annotated.
63
64
  * 100% test coverage.
@@ -96,15 +97,15 @@ pip install httpx2[http2]
96
97
 
97
98
  ## Documentation
98
99
 
99
- Project documentation is available at [https://httpx2.pydantic.dev/](https://httpx2.pydantic.dev/).
100
+ Project documentation is available at [https://pydantic.dev/docs/httpx2/](https://pydantic.dev/docs/httpx2/).
100
101
 
101
- For a run-through of all the basics, head over to the [QuickStart](https://httpx2.pydantic.dev/quickstart/).
102
+ For a run-through of all the basics, head over to the [QuickStart](https://pydantic.dev/docs/httpx2/get-started/quickstart/).
102
103
 
103
- For more advanced topics, see the [Advanced Usage](https://httpx2.pydantic.dev/advanced/) section, the [async support](https://httpx2.pydantic.dev/async/) section, or the [HTTP/2](https://httpx2.pydantic.dev/http2/) section.
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.
104
105
 
105
- The [Developer Interface](https://httpx2.pydantic.dev/api/) provides a comprehensive API reference.
106
+ The [Developer Interface](https://pydantic.dev/docs/httpx2/api/api/) provides a comprehensive API reference.
106
107
 
107
- To find out about tools that integrate with HTTPX, see [Third Party Packages](https://httpx2.pydantic.dev/third_party_packages/).
108
+ To find out about tools that integrate with HTTPX, see [Third Party Packages](https://pydantic.dev/docs/httpx2/community/third_party_packages/).
108
109
 
109
110
  ## Observability with Pydantic Logfire
110
111
 
@@ -130,7 +131,7 @@ This works the same way for explicit `httpx2.Client()` and `httpx2.AsyncClient()
130
131
 
131
132
  ## Contribute
132
133
 
133
- If you want to contribute with HTTPX2 check out the [Contributing Guide](https://httpx2.pydantic.dev/contributing/) to learn how to start.
134
+ If you want to contribute with HTTPX2 check out the [Contributing Guide](https://pydantic.dev/docs/httpx2/community/contributing/) to learn how to start.
134
135
 
135
136
  ## Dependencies
136
137
 
@@ -14,82 +14,96 @@ from ._types import *
14
14
  from ._urls import *
15
15
 
16
16
  __all__ = [
17
+ # __version__.py
17
18
  "__description__",
18
19
  "__title__",
19
20
  "__version__",
21
+ # _alias.py
20
22
  "alias_httpx",
21
- "ASGITransport",
22
- "AsyncBaseTransport",
23
- "AsyncByteStream",
24
- "AsyncClient",
25
- "AsyncHTTPTransport",
23
+ # _api.py
24
+ "delete",
25
+ "get",
26
+ "head",
27
+ "options",
28
+ "patch",
29
+ "post",
30
+ "put",
31
+ "query",
32
+ "request",
33
+ "stream",
34
+ "websocket",
35
+ # _auth.py
26
36
  "Auth",
27
- "BaseTransport",
28
37
  "BasicAuth",
29
- "ByteStream",
38
+ "DigestAuth",
39
+ "FunctionAuth",
40
+ "NetRCAuth",
41
+ # _client.py
42
+ "AsyncClient",
30
43
  "Client",
44
+ "USE_CLIENT_DEFAULT",
45
+ # _config.py
46
+ "create_ssl_context",
47
+ "Limits",
48
+ "Proxy",
49
+ "Timeout",
50
+ # _content.py
51
+ "ByteStream",
52
+ # _exceptions.py
31
53
  "CloseError",
32
- "codes",
33
54
  "ConnectError",
34
55
  "ConnectTimeout",
35
56
  "CookieConflict",
36
- "Cookies",
37
- "create_ssl_context",
38
57
  "DecodingError",
39
- "delete",
40
- "DigestAuth",
41
- "EventSource",
42
- "FunctionAuth",
43
- "get",
44
- "head",
45
- "Headers",
46
58
  "HTTPError",
47
59
  "HTTPStatusError",
48
- "HTTPTransport",
49
60
  "InvalidURL",
50
- "Limits",
51
61
  "LocalProtocolError",
52
- "MockTransport",
53
- "NetRCAuth",
54
62
  "NetworkError",
55
- "options",
56
- "Origin",
57
- "patch",
58
63
  "PoolTimeout",
59
- "post",
60
64
  "ProtocolError",
61
- "Proxy",
62
65
  "ProxyError",
63
- "put",
64
- "query",
65
- "QueryParams",
66
66
  "ReadError",
67
67
  "ReadTimeout",
68
68
  "RemoteProtocolError",
69
- "request",
70
- "Request",
71
69
  "RequestError",
72
70
  "RequestNotRead",
73
- "Response",
74
71
  "ResponseNotRead",
75
- "ServerSentEvent",
76
- "SSEError",
77
- "stream",
78
72
  "StreamClosed",
79
73
  "StreamConsumed",
80
74
  "StreamError",
81
- "SyncByteStream",
82
- "Timeout",
83
75
  "TimeoutException",
84
76
  "TooManyRedirects",
85
77
  "TransportError",
86
78
  "UnsupportedProtocol",
87
- "URL",
88
- "USE_CLIENT_DEFAULT",
89
- "websocket",
90
79
  "WriteError",
91
80
  "WriteTimeout",
81
+ # _models.py
82
+ "Cookies",
83
+ "Headers",
84
+ "Request",
85
+ "Response",
86
+ # _sse.py
87
+ "EventSource",
88
+ "ServerSentEvent",
89
+ "SSEError",
90
+ # _status_codes.py
91
+ "codes",
92
+ # _transports
93
+ "ASGITransport",
94
+ "AsyncBaseTransport",
95
+ "AsyncHTTPTransport",
96
+ "BaseTransport",
97
+ "HTTPTransport",
98
+ "MockTransport",
92
99
  "WSGITransport",
100
+ # _types.py
101
+ "AsyncByteStream",
102
+ "SyncByteStream",
103
+ # _urls.py
104
+ "Origin",
105
+ "QueryParams",
106
+ "URL",
93
107
  ]
94
108
 
95
109
 
@@ -146,7 +146,7 @@ def stream(
146
146
 
147
147
  See also: [Streaming Responses][0]
148
148
 
149
- [0]: /quickstart#streaming-responses
149
+ [0]: quickstart.md#streaming-responses
150
150
  """
151
151
  with Client(
152
152
  cookies=cookies,
@@ -262,7 +262,7 @@ class BaseClient:
262
262
 
263
263
  See also [Authentication][0].
264
264
 
265
- [0]: /quickstart/#authentication
265
+ [0]: quickstart.md#authentication
266
266
  """
267
267
  return self._auth
268
268
 
@@ -347,7 +347,7 @@ class BaseClient:
347
347
 
348
348
  See also: [Request instances][0]
349
349
 
350
- [0]: /advanced/clients/#request-instances
350
+ [0]: advanced/clients.md#request-instances
351
351
  """
352
352
  url = self._merge_url(url)
353
353
  headers = self._merge_headers(headers)
@@ -771,7 +771,7 @@ class Client(BaseClient):
771
771
  [Merging of configuration][0] for how the various parameters
772
772
  are merged with client-level configuration.
773
773
 
774
- [0]: /advanced/clients/#merging-of-configuration
774
+ [0]: advanced/clients.md#merging-of-configuration
775
775
  """
776
776
  if cookies is not None:
777
777
  message = (
@@ -822,7 +822,7 @@ class Client(BaseClient):
822
822
 
823
823
  See also: [Streaming Responses][0]
824
824
 
825
- [0]: /quickstart#streaming-responses
825
+ [0]: quickstart.md#streaming-responses
826
826
  """
827
827
  request = self.build_request(
828
828
  method=method,
@@ -965,7 +965,7 @@ class Client(BaseClient):
965
965
 
966
966
  See also: [Request instances][0]
967
967
 
968
- [0]: /advanced/clients/#request-instances
968
+ [0]: advanced/clients.md#request-instances
969
969
  """
970
970
  if self._state == ClientState.CLOSED:
971
971
  raise RuntimeError("Cannot send a request, as the client has been closed.")
@@ -1608,7 +1608,7 @@ class AsyncClient(BaseClient):
1608
1608
  and [Merging of configuration][0] for how the various parameters
1609
1609
  are merged with client-level configuration.
1610
1610
 
1611
- [0]: /advanced/clients/#merging-of-configuration
1611
+ [0]: advanced/clients.md#merging-of-configuration
1612
1612
  """
1613
1613
 
1614
1614
  if cookies is not None: # pragma: no cover
@@ -1660,7 +1660,7 @@ class AsyncClient(BaseClient):
1660
1660
 
1661
1661
  See also: [Streaming Responses][0]
1662
1662
 
1663
- [0]: /quickstart#streaming-responses
1663
+ [0]: quickstart.md#streaming-responses
1664
1664
  """
1665
1665
  request = self.build_request(
1666
1666
  method=method,
@@ -1803,7 +1803,7 @@ class AsyncClient(BaseClient):
1803
1803
 
1804
1804
  See also: [Request instances][0]
1805
1805
 
1806
- [0]: /advanced/clients/#request-instances
1806
+ [0]: advanced/clients.md#request-instances
1807
1807
  """
1808
1808
  if self._state == ClientState.CLOSED:
1809
1809
  raise RuntimeError("Cannot send a request, as the client has been closed.")
@@ -1,5 +1,6 @@
1
1
  from __future__ import annotations
2
2
 
3
+ import dataclasses
3
4
  import os
4
5
  import typing
5
6
 
@@ -75,6 +76,7 @@ def create_ssl_context(
75
76
  return ctx
76
77
 
77
78
 
79
+ @dataclasses.dataclass(init=False, repr=False)
78
80
  class Timeout:
79
81
  """
80
82
  Timeout configuration.
@@ -145,15 +147,6 @@ class Timeout:
145
147
  "pool": self.pool,
146
148
  }
147
149
 
148
- def __eq__(self, other: typing.Any) -> bool:
149
- return (
150
- isinstance(other, self.__class__)
151
- and self.connect == other.connect
152
- and self.read == other.read
153
- and self.write == other.write
154
- and self.pool == other.pool
155
- )
156
-
157
150
  def __repr__(self) -> str:
158
151
  class_name = self.__class__.__name__
159
152
  if len({self.connect, self.read, self.write, self.pool}) == 1:
@@ -161,6 +154,7 @@ class Timeout:
161
154
  return f"{class_name}(connect={self.connect}, read={self.read}, write={self.write}, pool={self.pool})"
162
155
 
163
156
 
157
+ @dataclasses.dataclass(kw_only=True)
164
158
  class Limits:
165
159
  """
166
160
  Configuration for limits to various client behaviors.
@@ -175,32 +169,9 @@ class Limits:
175
169
  * **keepalive_expiry** - Time limit on idle keep-alive connections in seconds.
176
170
  """
177
171
 
178
- def __init__(
179
- self,
180
- *,
181
- max_connections: int | None = None,
182
- max_keepalive_connections: int | None = None,
183
- keepalive_expiry: float | None = 5.0,
184
- ) -> None:
185
- self.max_connections = max_connections
186
- self.max_keepalive_connections = max_keepalive_connections
187
- self.keepalive_expiry = keepalive_expiry
188
-
189
- def __eq__(self, other: typing.Any) -> bool:
190
- return (
191
- isinstance(other, self.__class__)
192
- and self.max_connections == other.max_connections
193
- and self.max_keepalive_connections == other.max_keepalive_connections
194
- and self.keepalive_expiry == other.keepalive_expiry
195
- )
196
-
197
- def __repr__(self) -> str:
198
- class_name = self.__class__.__name__
199
- return (
200
- f"{class_name}(max_connections={self.max_connections}, "
201
- f"max_keepalive_connections={self.max_keepalive_connections}, "
202
- f"keepalive_expiry={self.keepalive_expiry})"
203
- )
172
+ max_connections: int | None = None
173
+ max_keepalive_connections: int | None = None
174
+ keepalive_expiry: float | None = 5.0
204
175
 
205
176
 
206
177
  class Proxy:
@@ -19,7 +19,7 @@ from ._types import (
19
19
  ResponseContent,
20
20
  SyncByteStream,
21
21
  )
22
- from ._utils import peek_filelike_length, primitive_value_to_str
22
+ from ._utils import peek_filelike_remaining_length, primitive_value_to_str
23
23
 
24
24
  __all__ = ["ByteStream"]
25
25
 
@@ -119,7 +119,7 @@ def encode_content(
119
119
  # catches a case that's easy for users to make in error, and would
120
120
  # otherwise pass through here, like any other bytes-iterable,
121
121
  # because `dict` happens to be iterable. See issue #2491.
122
- content_length_or_none = peek_filelike_length(content)
122
+ content_length_or_none = peek_filelike_remaining_length(content)
123
123
 
124
124
  if content_length_or_none is None:
125
125
  headers = {"Transfer-Encoding": "chunked"}
@@ -77,7 +77,7 @@ def print_help() -> None:
77
77
  )
78
78
 
79
79
  table.add_row("--follow-redirects", "Automatically follow redirects.")
80
- table.add_row("--no-verify", "Disable SSL verification.")
80
+ table.add_row("--verify / --no-verify", "Enable SSL verification.")
81
81
  table.add_row("--http2", "Send the request using HTTP/2, if the remote server supports it.")
82
82
 
83
83
  table.add_row(
@@ -393,11 +393,9 @@ def handle_help(
393
393
  help="Automatically follow redirects.",
394
394
  )
395
395
  @click.option(
396
- "--no-verify",
397
- "verify",
398
- is_flag=True,
396
+ "--verify/--no-verify",
399
397
  default=True,
400
- help="Disable SSL verification.",
398
+ help="Enable SSL verification.",
401
399
  )
402
400
  @click.option(
403
401
  "--http2",
@@ -34,7 +34,7 @@ class URL:
34
34
  assert url.port == 1234
35
35
  assert url.netloc == b"xn--mller-kva.de:1234"
36
36
  assert url.path == "/pa th"
37
- assert url.query == b"?search=ab"
37
+ assert url.query == b"search=ab"
38
38
  assert url.raw_path == b"/pa%20th?search=ab"
39
39
  assert url.fragment == "anchorlink"
40
40
 
@@ -115,6 +115,18 @@ def peek_filelike_length(stream: typing.Any) -> int | None:
115
115
  return length
116
116
 
117
117
 
118
+ def peek_filelike_remaining_length(stream: typing.Any) -> int | None:
119
+ """Return the remaining byte length without changing the stream position."""
120
+ try:
121
+ offset: int = stream.tell()
122
+ length: int = stream.seek(0, os.SEEK_END)
123
+ stream.seek(offset)
124
+ except (AttributeError, OSError):
125
+ return None
126
+
127
+ return max(0, length - offset)
128
+
129
+
118
130
  class URLPattern:
119
131
  """
120
132
  A utility class currently used for making lookups against proxy keys...
@@ -557,7 +557,10 @@ class WebSocketSession:
557
557
  should_close = self._wait_until_closed(self._should_close.wait, interval_seconds)
558
558
  if should_close: # pragma: no cover
559
559
  raise ShouldClose()
560
- pong_callback = self.ping()
560
+ try:
561
+ pong_callback = self.ping()
562
+ except wsproto.utilities.LocalProtocolError:
563
+ return
561
564
  if timeout_seconds is not None:
562
565
  acknowledged = self._wait_until_closed(pong_callback.wait, timeout_seconds)
563
566
  if not acknowledged:
@@ -41,7 +41,7 @@ class WebSocketDisconnect(HTTPXWSException):
41
41
 
42
42
  class WebSocketInvalidTypeReceived(HTTPXWSException):
43
43
  """
44
- Raised when a event is not of the expected type.
44
+ Raised when an event is not of the expected type.
45
45
  """
46
46
 
47
47
  def __init__(self, event: wsproto.events.Event) -> None:
@@ -1,5 +1,5 @@
1
1
  [build-system]
2
- requires = ["hatchling", "hatch-fancy-pypi-readme", "uv-dynamic-versioning>=0.14.0"]
2
+ requires = ["hatchling", "hatch-fancy-pypi-readme", "uv-dynamic-versioning>=0.14.1"]
3
3
  build-backend = "hatchling.build"
4
4
 
5
5
  [tool.hatch.version]
@@ -56,7 +56,7 @@ dependencies = [
56
56
  [project.optional-dependencies]
57
57
  brotli = [
58
58
  "brotli>=1.2.0; platform_python_implementation == 'CPython'",
59
- "brotlicffi>=1.2.0.0; platform_python_implementation != 'CPython'",
59
+ "brotlicffi>=1.2.0.2; platform_python_implementation != 'CPython'",
60
60
  ]
61
61
  cli = [
62
62
  "click>=8.4.2",
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