httpcore2 2.4.0__tar.gz → 2.6.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 (38) hide show
  1. {httpcore2-2.4.0 → httpcore2-2.6.0}/CHANGELOG.md +6 -0
  2. {httpcore2-2.4.0 → httpcore2-2.6.0}/PKG-INFO +7 -1
  3. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_async/connection.py +3 -0
  4. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_async/connection_pool.py +9 -0
  5. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_async/http11.py +7 -1
  6. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_async/http2.py +7 -1
  7. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_async/http_proxy.py +6 -0
  8. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_async/interfaces.py +12 -0
  9. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_async/socks_proxy.py +14 -6
  10. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_sync/connection.py +3 -0
  11. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_sync/connection_pool.py +9 -0
  12. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_sync/http11.py +7 -1
  13. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_sync/http2.py +7 -1
  14. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_sync/http_proxy.py +6 -0
  15. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_sync/interfaces.py +12 -0
  16. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_sync/socks_proxy.py +14 -6
  17. {httpcore2-2.4.0 → httpcore2-2.6.0}/.gitignore +0 -0
  18. {httpcore2-2.4.0 → httpcore2-2.6.0}/LICENSE.md +0 -0
  19. {httpcore2-2.4.0 → httpcore2-2.6.0}/README.md +0 -0
  20. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/__init__.py +0 -0
  21. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_api.py +0 -0
  22. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_async/__init__.py +0 -0
  23. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_backends/__init__.py +0 -0
  24. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_backends/anyio.py +0 -0
  25. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_backends/auto.py +0 -0
  26. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_backends/base.py +0 -0
  27. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_backends/mock.py +0 -0
  28. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_backends/sync.py +0 -0
  29. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_backends/trio.py +0 -0
  30. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_exceptions.py +0 -0
  31. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_models.py +0 -0
  32. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_ssl.py +0 -0
  33. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_sync/__init__.py +0 -0
  34. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_synchronization.py +0 -0
  35. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_trace.py +0 -0
  36. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/_utils.py +0 -0
  37. {httpcore2-2.4.0 → httpcore2-2.6.0}/httpcore2/py.typed +0 -0
  38. {httpcore2-2.4.0 → httpcore2-2.6.0}/pyproject.toml +0 -0
@@ -4,6 +4,12 @@ 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.5.0 (June 25th, 2026)
8
+
9
+ ### Fixed
10
+
11
+ * Propagate the timeout through the SOCKS5 handshake. ([#1009](https://github.com/pydantic/httpx2/pull/1009))
12
+
7
13
  ## 2.4.0 (June 11th, 2026)
8
14
 
9
15
  ### Fixed
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: httpcore2
3
- Version: 2.4.0
3
+ Version: 2.6.0
4
4
  Summary: A minimal low-level HTTP client.
5
5
  Project-URL: Changelog, https://github.com/pydantic/httpx2/blob/main/src/httpcore2/CHANGELOG.md
6
6
  Project-URL: Homepage, https://github.com/pydantic/httpx2
@@ -151,6 +151,12 @@ All notable changes to this project will be documented in this file.
151
151
 
152
152
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
153
153
 
154
+ ## 2.5.0 (June 25th, 2026)
155
+
156
+ ### Fixed
157
+
158
+ * Propagate the timeout through the SOCKS5 handshake. ([#1009](https://github.com/pydantic/httpx2/pull/1009))
159
+
154
160
  ## 2.4.0 (June 11th, 2026)
155
161
 
156
162
  ### Fixed
@@ -156,6 +156,9 @@ class AsyncHTTPConnection(AsyncConnectionInterface):
156
156
  async with Trace("close", logger, None, {}):
157
157
  await self._connection.aclose()
158
158
 
159
+ def is_connected(self) -> bool:
160
+ return self._connection is not None and self._connection.is_connected()
161
+
159
162
  def is_available(self) -> bool:
160
163
  if self._connection is None:
161
164
  # If HTTP/2 support is enabled, and the resulting connection could
@@ -264,11 +264,20 @@ class AsyncConnectionPool(AsyncRequestInterface):
264
264
  closing_connections: list[AsyncConnectionInterface] = []
265
265
  retained_connections: list[AsyncConnectionInterface] = []
266
266
 
267
+ # Connections currently referenced by an active request (including
268
+ # connections that are in the process of being established).
269
+ request_connections = {r.connection for r in self._requests}
270
+
267
271
  # First we handle cleaning up any connections that are closed
268
272
  # or have expired their keep-alive, in a single pass.
269
273
  for connection in self._connections:
270
274
  if connection.is_closed():
271
275
  continue
276
+ elif not (connection.is_connected() or connection in request_connections):
277
+ # Garbage: a NEW-state connection whose request was cancelled
278
+ # before the TCP handshake completed. Drop it without closing
279
+ # (there is no socket to close yet).
280
+ continue
272
281
  elif connection.has_expired():
273
282
  closing_connections.append(connection)
274
283
  else:
@@ -242,6 +242,9 @@ class AsyncHTTP11Connection(AsyncConnectionInterface):
242
242
  def can_handle_request(self, origin: Origin) -> bool:
243
243
  return origin == self._origin
244
244
 
245
+ def is_connected(self) -> bool:
246
+ return not self.is_closed()
247
+
245
248
  def is_available(self) -> bool:
246
249
  # Note that HTTP/1.1 connections in the "NEW" state are not treated as
247
250
  # being "available". The control flow which created the connection will
@@ -251,7 +254,10 @@ class AsyncHTTP11Connection(AsyncConnectionInterface):
251
254
 
252
255
  def has_expired(self) -> bool:
253
256
  now = time.monotonic()
254
- keepalive_expired = self._expire_at is not None and now > self._expire_at
257
+ # Read `_expire_at` once into a local: on free-threaded builds another
258
+ # thread may reset it to `None` between the check and the comparison.
259
+ expire_at = self._expire_at
260
+ keepalive_expired = expire_at is not None and now > expire_at
255
261
 
256
262
  # If the HTTP connection is idle but the socket is readable, then the
257
263
  # only valid state is that the socket is about to return b"", indicating
@@ -474,6 +474,9 @@ class AsyncHTTP2Connection(AsyncConnectionInterface):
474
474
  def can_handle_request(self, origin: Origin) -> bool:
475
475
  return origin == self._origin
476
476
 
477
+ def is_connected(self) -> bool:
478
+ return not self.is_closed()
479
+
477
480
  def is_available(self) -> bool:
478
481
  return (
479
482
  self._state != HTTPConnectionState.CLOSED
@@ -484,7 +487,10 @@ class AsyncHTTP2Connection(AsyncConnectionInterface):
484
487
 
485
488
  def has_expired(self) -> bool:
486
489
  now = time.monotonic()
487
- return self._expire_at is not None and now > self._expire_at
490
+ # Read `_expire_at` once into a local: on free-threaded builds another
491
+ # thread may reset it to `None` between the check and the comparison.
492
+ expire_at = self._expire_at
493
+ return expire_at is not None and now > expire_at
488
494
 
489
495
  def is_idle(self) -> bool:
490
496
  return self._state == HTTPConnectionState.IDLE
@@ -204,6 +204,9 @@ class AsyncForwardHTTPConnection(AsyncConnectionInterface):
204
204
  def info(self) -> str:
205
205
  return self._connection.info()
206
206
 
207
+ def is_connected(self) -> bool:
208
+ return self._connection.is_connected()
209
+
207
210
  def is_available(self) -> bool:
208
211
  return self._connection.is_available()
209
212
 
@@ -330,6 +333,9 @@ class AsyncTunnelHTTPConnection(AsyncConnectionInterface):
330
333
  def info(self) -> str:
331
334
  return self._connection.info()
332
335
 
336
+ def is_connected(self) -> bool:
337
+ return self._connection.is_connected()
338
+
333
339
  def is_available(self) -> bool:
334
340
  return self._connection.is_available()
335
341
 
@@ -95,6 +95,18 @@ class AsyncConnectionInterface(AsyncRequestInterface):
95
95
  def can_handle_request(self, origin: Origin) -> bool:
96
96
  raise NotImplementedError() # pragma: no cover
97
97
 
98
+ def is_connected(self) -> bool:
99
+ """
100
+ Return `True` if the connection is open (the underlying socket has been
101
+ established). A connection in the NEW state (just created but not yet
102
+ connected) returns `False`.
103
+
104
+ Note: for some implementations `is_connected() != not is_closed()`.
105
+ The default implementation returns `not self.is_closed()`, which is
106
+ correct for connections that are never in the NEW (pre-TCP) state.
107
+ """
108
+ return not self.is_closed() # pragma: no cover
109
+
98
110
  def is_available(self) -> bool:
99
111
  """
100
112
  Return `True` if the connection is currently able to accept an
@@ -45,7 +45,11 @@ async def _init_socks5_connection(
45
45
  host: bytes,
46
46
  port: int,
47
47
  auth: tuple[bytes, bytes] | None = None,
48
+ timeouts: dict[str, float | None] | None = None,
48
49
  ) -> None:
50
+ timeouts = timeouts or {}
51
+ write_timeout = timeouts.get("write", None)
52
+ read_timeout = timeouts.get("read", None)
49
53
  conn = socksio.socks5.SOCKS5Connection()
50
54
 
51
55
  # Auth method request
@@ -56,10 +60,10 @@ async def _init_socks5_connection(
56
60
  )
57
61
  conn.send(socksio.socks5.SOCKS5AuthMethodsRequest([auth_method]))
58
62
  outgoing_bytes = conn.data_to_send()
59
- await stream.write(outgoing_bytes)
63
+ await stream.write(outgoing_bytes, timeout=write_timeout)
60
64
 
61
65
  # Auth method response
62
- incoming_bytes = await stream.read(max_bytes=4096)
66
+ incoming_bytes = await stream.read(max_bytes=4096, timeout=read_timeout)
63
67
  response = conn.receive_data(incoming_bytes)
64
68
  assert isinstance(response, socksio.socks5.SOCKS5AuthReply)
65
69
  if response.method != auth_method:
@@ -73,10 +77,10 @@ async def _init_socks5_connection(
73
77
  username, password = auth
74
78
  conn.send(socksio.socks5.SOCKS5UsernamePasswordRequest(username, password))
75
79
  outgoing_bytes = conn.data_to_send()
76
- await stream.write(outgoing_bytes)
80
+ await stream.write(outgoing_bytes, timeout=write_timeout)
77
81
 
78
82
  # Username/password response
79
- incoming_bytes = await stream.read(max_bytes=4096)
83
+ incoming_bytes = await stream.read(max_bytes=4096, timeout=read_timeout)
80
84
  response = conn.receive_data(incoming_bytes)
81
85
  assert isinstance(response, socksio.socks5.SOCKS5UsernamePasswordReply)
82
86
  if not response.success:
@@ -85,10 +89,10 @@ async def _init_socks5_connection(
85
89
  # Connect request
86
90
  conn.send(socksio.socks5.SOCKS5CommandRequest.from_address(socksio.socks5.SOCKS5Command.CONNECT, (host, port)))
87
91
  outgoing_bytes = conn.data_to_send()
88
- await stream.write(outgoing_bytes)
92
+ await stream.write(outgoing_bytes, timeout=write_timeout)
89
93
 
90
94
  # Connect response
91
- incoming_bytes = await stream.read(max_bytes=4096)
95
+ incoming_bytes = await stream.read(max_bytes=4096, timeout=read_timeout)
92
96
  response = conn.receive_data(incoming_bytes)
93
97
  assert isinstance(response, socksio.socks5.SOCKS5Reply)
94
98
  if response.reply_code != socksio.socks5.SOCKS5ReplyCode.SUCCEEDED:
@@ -229,6 +233,7 @@ class AsyncSocks5Connection(AsyncConnectionInterface):
229
233
  "host": self._remote_origin.host.decode("ascii"),
230
234
  "port": self._remote_origin.port,
231
235
  "auth": self._proxy_auth,
236
+ "timeouts": timeouts,
232
237
  }
233
238
  async with Trace("setup_socks5_connection", logger, request, kwargs) as trace:
234
239
  await _init_socks5_connection(**kwargs)
@@ -283,6 +288,9 @@ class AsyncSocks5Connection(AsyncConnectionInterface):
283
288
  if self._connection is not None:
284
289
  await self._connection.aclose()
285
290
 
291
+ def is_connected(self) -> bool:
292
+ return self._connection is not None and self._connection.is_connected()
293
+
286
294
  def is_available(self) -> bool:
287
295
  if self._connection is None: # pragma: no cover
288
296
  # If HTTP/2 support is enabled, and the resulting connection could
@@ -156,6 +156,9 @@ class HTTPConnection(ConnectionInterface):
156
156
  with Trace("close", logger, None, {}):
157
157
  self._connection.close()
158
158
 
159
+ def is_connected(self) -> bool:
160
+ return self._connection is not None and self._connection.is_connected()
161
+
159
162
  def is_available(self) -> bool:
160
163
  if self._connection is None:
161
164
  # If HTTP/2 support is enabled, and the resulting connection could
@@ -264,11 +264,20 @@ class ConnectionPool(RequestInterface):
264
264
  closing_connections: list[ConnectionInterface] = []
265
265
  retained_connections: list[ConnectionInterface] = []
266
266
 
267
+ # Connections currently referenced by an active request (including
268
+ # connections that are in the process of being established).
269
+ request_connections = {r.connection for r in self._requests}
270
+
267
271
  # First we handle cleaning up any connections that are closed
268
272
  # or have expired their keep-alive, in a single pass.
269
273
  for connection in self._connections:
270
274
  if connection.is_closed():
271
275
  continue
276
+ elif not (connection.is_connected() or connection in request_connections):
277
+ # Garbage: a NEW-state connection whose request was cancelled
278
+ # before the TCP handshake completed. Drop it without closing
279
+ # (there is no socket to close yet).
280
+ continue
272
281
  elif connection.has_expired():
273
282
  closing_connections.append(connection)
274
283
  else:
@@ -242,6 +242,9 @@ class HTTP11Connection(ConnectionInterface):
242
242
  def can_handle_request(self, origin: Origin) -> bool:
243
243
  return origin == self._origin
244
244
 
245
+ def is_connected(self) -> bool:
246
+ return not self.is_closed()
247
+
245
248
  def is_available(self) -> bool:
246
249
  # Note that HTTP/1.1 connections in the "NEW" state are not treated as
247
250
  # being "available". The control flow which created the connection will
@@ -251,7 +254,10 @@ class HTTP11Connection(ConnectionInterface):
251
254
 
252
255
  def has_expired(self) -> bool:
253
256
  now = time.monotonic()
254
- keepalive_expired = self._expire_at is not None and now > self._expire_at
257
+ # Read `_expire_at` once into a local: on free-threaded builds another
258
+ # thread may reset it to `None` between the check and the comparison.
259
+ expire_at = self._expire_at
260
+ keepalive_expired = expire_at is not None and now > expire_at
255
261
 
256
262
  # If the HTTP connection is idle but the socket is readable, then the
257
263
  # only valid state is that the socket is about to return b"", indicating
@@ -474,6 +474,9 @@ class HTTP2Connection(ConnectionInterface):
474
474
  def can_handle_request(self, origin: Origin) -> bool:
475
475
  return origin == self._origin
476
476
 
477
+ def is_connected(self) -> bool:
478
+ return not self.is_closed()
479
+
477
480
  def is_available(self) -> bool:
478
481
  return (
479
482
  self._state != HTTPConnectionState.CLOSED
@@ -484,7 +487,10 @@ class HTTP2Connection(ConnectionInterface):
484
487
 
485
488
  def has_expired(self) -> bool:
486
489
  now = time.monotonic()
487
- return self._expire_at is not None and now > self._expire_at
490
+ # Read `_expire_at` once into a local: on free-threaded builds another
491
+ # thread may reset it to `None` between the check and the comparison.
492
+ expire_at = self._expire_at
493
+ return expire_at is not None and now > expire_at
488
494
 
489
495
  def is_idle(self) -> bool:
490
496
  return self._state == HTTPConnectionState.IDLE
@@ -204,6 +204,9 @@ class ForwardHTTPConnection(ConnectionInterface):
204
204
  def info(self) -> str:
205
205
  return self._connection.info()
206
206
 
207
+ def is_connected(self) -> bool:
208
+ return self._connection.is_connected()
209
+
207
210
  def is_available(self) -> bool:
208
211
  return self._connection.is_available()
209
212
 
@@ -330,6 +333,9 @@ class TunnelHTTPConnection(ConnectionInterface):
330
333
  def info(self) -> str:
331
334
  return self._connection.info()
332
335
 
336
+ def is_connected(self) -> bool:
337
+ return self._connection.is_connected()
338
+
333
339
  def is_available(self) -> bool:
334
340
  return self._connection.is_available()
335
341
 
@@ -95,6 +95,18 @@ class ConnectionInterface(RequestInterface):
95
95
  def can_handle_request(self, origin: Origin) -> bool:
96
96
  raise NotImplementedError() # pragma: no cover
97
97
 
98
+ def is_connected(self) -> bool:
99
+ """
100
+ Return `True` if the connection is open (the underlying socket has been
101
+ established). A connection in the NEW state (just created but not yet
102
+ connected) returns `False`.
103
+
104
+ Note: for some implementations `is_connected() != not is_closed()`.
105
+ The default implementation returns `not self.is_closed()`, which is
106
+ correct for connections that are never in the NEW (pre-TCP) state.
107
+ """
108
+ return not self.is_closed() # pragma: no cover
109
+
98
110
  def is_available(self) -> bool:
99
111
  """
100
112
  Return `True` if the connection is currently able to accept an
@@ -45,7 +45,11 @@ def _init_socks5_connection(
45
45
  host: bytes,
46
46
  port: int,
47
47
  auth: tuple[bytes, bytes] | None = None,
48
+ timeouts: dict[str, float | None] | None = None,
48
49
  ) -> None:
50
+ timeouts = timeouts or {}
51
+ write_timeout = timeouts.get("write", None)
52
+ read_timeout = timeouts.get("read", None)
49
53
  conn = socksio.socks5.SOCKS5Connection()
50
54
 
51
55
  # Auth method request
@@ -56,10 +60,10 @@ def _init_socks5_connection(
56
60
  )
57
61
  conn.send(socksio.socks5.SOCKS5AuthMethodsRequest([auth_method]))
58
62
  outgoing_bytes = conn.data_to_send()
59
- stream.write(outgoing_bytes)
63
+ stream.write(outgoing_bytes, timeout=write_timeout)
60
64
 
61
65
  # Auth method response
62
- incoming_bytes = stream.read(max_bytes=4096)
66
+ incoming_bytes = stream.read(max_bytes=4096, timeout=read_timeout)
63
67
  response = conn.receive_data(incoming_bytes)
64
68
  assert isinstance(response, socksio.socks5.SOCKS5AuthReply)
65
69
  if response.method != auth_method:
@@ -73,10 +77,10 @@ def _init_socks5_connection(
73
77
  username, password = auth
74
78
  conn.send(socksio.socks5.SOCKS5UsernamePasswordRequest(username, password))
75
79
  outgoing_bytes = conn.data_to_send()
76
- stream.write(outgoing_bytes)
80
+ stream.write(outgoing_bytes, timeout=write_timeout)
77
81
 
78
82
  # Username/password response
79
- incoming_bytes = stream.read(max_bytes=4096)
83
+ incoming_bytes = stream.read(max_bytes=4096, timeout=read_timeout)
80
84
  response = conn.receive_data(incoming_bytes)
81
85
  assert isinstance(response, socksio.socks5.SOCKS5UsernamePasswordReply)
82
86
  if not response.success:
@@ -85,10 +89,10 @@ def _init_socks5_connection(
85
89
  # Connect request
86
90
  conn.send(socksio.socks5.SOCKS5CommandRequest.from_address(socksio.socks5.SOCKS5Command.CONNECT, (host, port)))
87
91
  outgoing_bytes = conn.data_to_send()
88
- stream.write(outgoing_bytes)
92
+ stream.write(outgoing_bytes, timeout=write_timeout)
89
93
 
90
94
  # Connect response
91
- incoming_bytes = stream.read(max_bytes=4096)
95
+ incoming_bytes = stream.read(max_bytes=4096, timeout=read_timeout)
92
96
  response = conn.receive_data(incoming_bytes)
93
97
  assert isinstance(response, socksio.socks5.SOCKS5Reply)
94
98
  if response.reply_code != socksio.socks5.SOCKS5ReplyCode.SUCCEEDED:
@@ -229,6 +233,7 @@ class Socks5Connection(ConnectionInterface):
229
233
  "host": self._remote_origin.host.decode("ascii"),
230
234
  "port": self._remote_origin.port,
231
235
  "auth": self._proxy_auth,
236
+ "timeouts": timeouts,
232
237
  }
233
238
  with Trace("setup_socks5_connection", logger, request, kwargs) as trace:
234
239
  _init_socks5_connection(**kwargs)
@@ -283,6 +288,9 @@ class Socks5Connection(ConnectionInterface):
283
288
  if self._connection is not None:
284
289
  self._connection.close()
285
290
 
291
+ def is_connected(self) -> bool:
292
+ return self._connection is not None and self._connection.is_connected()
293
+
286
294
  def is_available(self) -> bool:
287
295
  if self._connection is None: # pragma: no cover
288
296
  # If HTTP/2 support is enabled, and the resulting connection could
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