1111from .._backends .auto import AsyncLock , AsyncSocketStream , AutoBackend
1212from .._exceptions import ProtocolError
1313from .._types import URL , Headers , TimeoutDict
14+ from .._utils import get_logger
1415from .base import (
1516 AsyncByteStream ,
1617 AsyncHTTPTransport ,
1718 ConnectionState ,
1819 NewConnectionRequired ,
1920)
2021
22+ logger = get_logger (__name__ )
23+
2124
2225def get_reason_phrase (status_code : int ) -> bytes :
2326 try :
@@ -128,6 +131,7 @@ async def send_connection_init(self, timeout: TimeoutDict) -> None:
128131 h2 .settings .SettingCodes .ENABLE_CONNECT_PROTOCOL
129132 ]
130133
134+ logger .trace ("initiate_connection=%r" , self )
131135 self .h2_state .initiate_connection ()
132136 self .h2_state .increment_flow_control_window (2 ** 24 )
133137 data_to_send = self .h2_state .data_to_send ()
@@ -141,6 +145,7 @@ def is_connection_dropped(self) -> bool:
141145 return self .socket .is_connection_dropped ()
142146
143147 async def aclose (self ) -> None :
148+ logger .trace ("close_connection=%r" , self )
144149 if self .state != ConnectionState .CLOSED :
145150 self .state = ConnectionState .CLOSED
146151
@@ -184,6 +189,7 @@ async def receive_events(self, timeout: TimeoutDict) -> None:
184189 events = self .h2_state .receive_data (data )
185190 for event in events :
186191 event_stream_id = getattr (event , "stream_id" , 0 )
192+ logger .trace ("receive_event stream_id=%r event=%s" , event_stream_id , event )
187193
188194 if hasattr (event , "error_code" ):
189195 raise ProtocolError (event )
@@ -197,6 +203,7 @@ async def receive_events(self, timeout: TimeoutDict) -> None:
197203 async def send_headers (
198204 self , stream_id : int , headers : Headers , end_stream : bool , timeout : TimeoutDict ,
199205 ) -> None :
206+ logger .trace ("send_headers stream_id=%r headers=%r" , stream_id , headers )
200207 self .h2_state .send_headers (stream_id , headers , end_stream = end_stream )
201208 self .h2_state .increment_flow_control_window (2 ** 24 , stream_id = stream_id )
202209 data_to_send = self .h2_state .data_to_send ()
@@ -205,11 +212,13 @@ async def send_headers(
205212 async def send_data (
206213 self , stream_id : int , chunk : bytes , timeout : TimeoutDict
207214 ) -> None :
215+ logger .trace ("send_data stream_id=%r chunk=%r" , stream_id , chunk )
208216 self .h2_state .send_data (stream_id , chunk )
209217 data_to_send = self .h2_state .data_to_send ()
210218 await self .socket .write (data_to_send , timeout )
211219
212220 async def end_stream (self , stream_id : int , timeout : TimeoutDict ) -> None :
221+ logger .trace ("end_stream stream_id=%r" , stream_id )
213222 self .h2_state .end_stream (stream_id )
214223 data_to_send = self .h2_state .data_to_send ()
215224 await self .socket .write (data_to_send , timeout )
@@ -222,6 +231,7 @@ async def acknowledge_received_data(
222231 await self .socket .write (data_to_send , timeout )
223232
224233 async def close_stream (self , stream_id : int ) -> None :
234+ logger .trace ("close_stream stream_id=%r" , stream_id )
225235 del self .streams [stream_id ]
226236 del self .events [stream_id ]
227237
0 commit comments