File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -199,6 +199,11 @@ def is_closed(self) -> bool:
199199 return self ._connect_failed
200200 return self ._connection .is_closed ()
201201
202+ def get_available_stream_capacity (self ) -> int :
203+ if self ._connection is None :
204+ return 1
205+ return self ._connection .get_available_stream_capacity ()
206+
202207 def info (self ) -> str :
203208 if self ._connection is None :
204209 return "CONNECTION FAILED" if self ._connect_failed else "CONNECTING"
Original file line number Diff line number Diff line change 1515
1616try :
1717 from .http2 import AsyncHTTP2Connection
18- except ImportError :
18+ except ImportError : # pragma: nocover
1919 # ImportError happens when the user installed httpcore without the optional http2 dependency
2020 AsyncHTTP2Connection = None # type: ignore[assignment, misc]
2121
@@ -303,7 +303,7 @@ def _assign_requests_to_connections(self) -> list[AsyncConnectionInterface]:
303303 # Available connections
304304 available_conns .append (conn )
305305 # Track HTTP/2 connection capacity
306- if self ._http2 and isinstance ( conn , AsyncHTTP2Connection ) :
306+ if self ._http2 :
307307 # Get the actual available stream count from the connection
308308 http2_conn_stream_capacity [conn ] = (
309309 conn .get_available_stream_capacity ()
Original file line number Diff line number Diff line change @@ -291,6 +291,13 @@ def is_idle(self) -> bool:
291291 def is_closed (self ) -> bool :
292292 return self ._state == HTTPConnectionState .CLOSED
293293
294+ def get_available_stream_capacity (self ) -> int :
295+ """
296+ For HTTP/1.1, return 1 if the connection is idle (can accept a request),
297+ 0 otherwise (connection is busy).
298+ """
299+ return 1 if self ._state == HTTPConnectionState .IDLE else 0
300+
294301 def info (self ) -> str :
295302 origin = str (self ._origin )
296303 return (
Original file line number Diff line number Diff line change @@ -363,5 +363,8 @@ def is_idle(self) -> bool:
363363 def is_closed (self ) -> bool :
364364 return self ._connection .is_closed ()
365365
366+ def get_available_stream_capacity (self ) -> int :
367+ return self ._connection .get_available_stream_capacity ()
368+
366369 def __repr__ (self ) -> str :
367370 return f"<{ self .__class__ .__name__ } [{ self .info ()} ]>"
Original file line number Diff line number Diff line change @@ -135,3 +135,12 @@ def is_closed(self) -> bool:
135135 returned to the connection pool or not.
136136 """
137137 raise NotImplementedError () # pragma: nocover
138+
139+ def get_available_stream_capacity (self ) -> int :
140+ """
141+ Return the number of additional streams that can be handled by this connection.
142+
143+ For HTTP/1.1 connections, this is 1 if the connection is idle, 0 otherwise.
144+ For HTTP/2 connections, this is the number of available concurrent streams.
145+ """
146+ raise NotImplementedError () # pragma: nocover
Original file line number Diff line number Diff line change @@ -199,6 +199,11 @@ def is_closed(self) -> bool:
199199 return self ._connect_failed
200200 return self ._connection .is_closed ()
201201
202+ def get_available_stream_capacity (self ) -> int :
203+ if self ._connection is None :
204+ return 1
205+ return self ._connection .get_available_stream_capacity ()
206+
202207 def info (self ) -> str :
203208 if self ._connection is None :
204209 return "CONNECTION FAILED" if self ._connect_failed else "CONNECTING"
Original file line number Diff line number Diff line change 1515
1616try :
1717 from .http2 import HTTP2Connection
18- except ImportError :
18+ except ImportError : # pragma: nocover
1919 # ImportError happens when the user installed httpcore without the optional http2 dependency
2020 HTTP2Connection = None # type: ignore[assignment, misc]
2121
@@ -303,7 +303,7 @@ def _assign_requests_to_connections(self) -> list[ConnectionInterface]:
303303 # Available connections
304304 available_conns .append (conn )
305305 # Track HTTP/2 connection capacity
306- if self ._http2 and isinstance ( conn , HTTP2Connection ) :
306+ if self ._http2 :
307307 # Get the actual available stream count from the connection
308308 http2_conn_stream_capacity [conn ] = (
309309 conn .get_available_stream_capacity ()
Original file line number Diff line number Diff line change @@ -291,6 +291,13 @@ def is_idle(self) -> bool:
291291 def is_closed (self ) -> bool :
292292 return self ._state == HTTPConnectionState .CLOSED
293293
294+ def get_available_stream_capacity (self ) -> int :
295+ """
296+ For HTTP/1.1, return 1 if the connection is idle (can accept a request),
297+ 0 otherwise (connection is busy).
298+ """
299+ return 1 if self ._state == HTTPConnectionState .IDLE else 0
300+
294301 def info (self ) -> str :
295302 origin = str (self ._origin )
296303 return (
Original file line number Diff line number Diff line change @@ -363,5 +363,8 @@ def is_idle(self) -> bool:
363363 def is_closed (self ) -> bool :
364364 return self ._connection .is_closed ()
365365
366+ def get_available_stream_capacity (self ) -> int :
367+ return self ._connection .get_available_stream_capacity ()
368+
366369 def __repr__ (self ) -> str :
367370 return f"<{ self .__class__ .__name__ } [{ self .info ()} ]>"
Original file line number Diff line number Diff line change @@ -135,3 +135,12 @@ def is_closed(self) -> bool:
135135 returned to the connection pool or not.
136136 """
137137 raise NotImplementedError () # pragma: nocover
138+
139+ def get_available_stream_capacity (self ) -> int :
140+ """
141+ Return the number of additional streams that can be handled by this connection.
142+
143+ For HTTP/1.1 connections, this is 1 if the connection is idle, 0 otherwise.
144+ For HTTP/2 connections, this is the number of available concurrent streams.
145+ """
146+ raise NotImplementedError () # pragma: nocover
You can’t perform that action at this time.
0 commit comments