httpcore2 2.5.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.
- {httpcore2-2.5.0 → httpcore2-2.6.0}/PKG-INFO +1 -1
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_async/connection.py +3 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_async/connection_pool.py +9 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_async/http11.py +7 -1
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_async/http2.py +7 -1
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_async/http_proxy.py +6 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_async/interfaces.py +12 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_async/socks_proxy.py +3 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_sync/connection.py +3 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_sync/connection_pool.py +9 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_sync/http11.py +7 -1
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_sync/http2.py +7 -1
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_sync/http_proxy.py +6 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_sync/interfaces.py +12 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_sync/socks_proxy.py +3 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/.gitignore +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/CHANGELOG.md +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/LICENSE.md +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/README.md +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/__init__.py +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_api.py +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_async/__init__.py +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_backends/__init__.py +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_backends/anyio.py +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_backends/auto.py +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_backends/base.py +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_backends/mock.py +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_backends/sync.py +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_backends/trio.py +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_exceptions.py +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_models.py +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_ssl.py +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_sync/__init__.py +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_synchronization.py +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_trace.py +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/_utils.py +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/httpcore2/py.typed +0 -0
- {httpcore2-2.5.0 → httpcore2-2.6.0}/pyproject.toml +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: httpcore2
|
|
3
|
-
Version: 2.
|
|
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
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
|
@@ -288,6 +288,9 @@ class AsyncSocks5Connection(AsyncConnectionInterface):
|
|
|
288
288
|
if self._connection is not None:
|
|
289
289
|
await self._connection.aclose()
|
|
290
290
|
|
|
291
|
+
def is_connected(self) -> bool:
|
|
292
|
+
return self._connection is not None and self._connection.is_connected()
|
|
293
|
+
|
|
291
294
|
def is_available(self) -> bool:
|
|
292
295
|
if self._connection is None: # pragma: no cover
|
|
293
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
|
-
|
|
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
|
-
|
|
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
|
|
@@ -288,6 +288,9 @@ class Socks5Connection(ConnectionInterface):
|
|
|
288
288
|
if self._connection is not None:
|
|
289
289
|
self._connection.close()
|
|
290
290
|
|
|
291
|
+
def is_connected(self) -> bool:
|
|
292
|
+
return self._connection is not None and self._connection.is_connected()
|
|
293
|
+
|
|
291
294
|
def is_available(self) -> bool:
|
|
292
295
|
if self._connection is None: # pragma: no cover
|
|
293
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
|
|
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
|