+
    jQ                     z    R t ^ RIt^RIHtHtHtHtHt ^RIH	t	 ^RI
Ht RsRsRsRsRsR t ! R R4      tR.tR# )z
Async HTTP/2 server connection implementation for ASGI workers.

Uses the hyper-h2 library for HTTP/2 protocol handling with
asyncio for non-blocking I/O.
N)
HTTP2ErrorHTTP2ProtocolErrorHTTP2ConnectionErrorHTTP2NotAvailableHTTP2ErrorCode)HTTP2Stream)HTTP2Requestc                     \         e   R#  ^ RIHs  ^ RIHs ^ RIHs ^ RI	H
s ^ RIHs R#   \         d    \!        4       hi ; i)z$Lazily import h2 library components.N)_h2h2.connection
connection	h2.configconfig
_h2_config	h2.eventsevents
_h2_eventsh2.exceptions
exceptions_h2_exceptionsh2.settingssettings_h2_settingsImportErrorr        T/var/www/idalgo/venv/lib/python3.14/site-packages/gunicorn/http2/async_connection.py
_import_h2r      s8     "#&&.* "!!"s	   , Ac                      a  ] tR t^0t o RtRtR tR tRR ltR t	R t
R	 tR
 tR tR tR tR tR tRR ltR tRR ltR tRR ltRR ltRR ltR t]R 4       tR tR tRtV tR# ) AsyncHTTP2ConnectionzAsync HTTP/2 server-side connection handler for ASGI.

Manages the HTTP/2 connection state and multiplexed streams
using asyncio for non-blocking I/O operations.
i   c                   \        4        Wn        W n        W0n        W@n        / V n        \        P                  ! 4       V n        VP                  V n
        VP                  V n        VP                  V n        VP                  V n        \"        P%                  RRR7      p\&        P)                  VR7      V n        RV n        RV n        RV n        R# )a  Initialize an async HTTP/2 server connection.

Args:
    cfg: Gunicorn configuration object
    reader: asyncio StreamReader
    writer: asyncio StreamWriter
    client_addr: Client address tuple (host, port)

Raises:
    HTTP2NotAvailable: If h2 library is not installed
Fzutf-8)client_sideheader_encoding)r   N)r   cfgreaderwriterclient_addrstreamsasyncioQueue_request_queuehttp2_initial_window_sizeinitial_window_sizehttp2_max_concurrent_streamsmax_concurrent_streamshttp2_max_frame_sizemax_frame_sizehttp2_max_header_list_sizemax_header_list_sizer   H2Configurationr
   H2Connectionh2_conn_closed_initialized_receive_task)selfr#   r$   r%   r&   r   s   &&&&& r   __init__AsyncHTTP2Connection.__init__:   s     	&  &mmo $'#@#@ &)&F&F#!66$'$B$B! ++# , 
 ''v'6 !!r   c           
       "   V P                   '       d   R# V P                  P                  \        P                  P
                  V P                  \        P                  P                  V P                  \        P                  P                  V P                  \        P                  P                  V P                  /4       V P                  P                  4        V P                  4       G Rj  xL
  RV n         R#  L5i)z|Send initial HTTP/2 settings to client.

Should be called after the SSL handshake completes and
before processing any data.
NT)r7   r5   update_settingsr   SettingCodesMAX_CONCURRENT_STREAMSr.   INITIAL_WINDOW_SIZEr,   MAX_FRAME_SIZEr0   MAX_HEADER_LIST_SIZEr2   initiate_connection_send_pending_datar9   s   &r   rC   (AsyncHTTP2Connection.initiate_connectione   s       	$$%%<<d>Y>Y%%994;S;S%%44d6I6I%%::D<U<U	&
 	 	((*%%'''  	(s   C-C?/C=0C?Nc                  "    VeE   \         P                  ! V P                  P                  V P                  4      VR7      G Rj  xL
 pM.V P                  P                  V P                  4      G Rj  xL
 p V'       g
   RV n        . #  V P                  P                  V4      p. pT F+  pT P5                  T4      pTf   K  TP7                  T4       K-  	  T P9                  4       G Rj  xL
  T#  L L  \
        \        3 d   p\        RT 24      hRp?ii ; i  \        P                   dC   pT P                  \        P                  R7      G Rj  xL 
  \!        \#        T4      4      hRp?i\        P$                   dC   pT P                  \        P&                  R7      G Rj  xL 
  \!        \#        T4      4      hRp?i\        P(                   dp   p\+        TRR4      pTe   T P                  TR7      G Rj  xL 
  M)T P                  \        P,                  R7      G Rj  xL 
  \!        \#        T4      4      hRp?i\        P.                   dC   pT P                  \        P0                  R7      G Rj  xL 
  \!        \#        T4      4      hRp?i\        P2                   dC   pT P                  \        P,                  R7      G Rj  xL 
  \!        \#        T4      4      hRp?ii ; i EL5i)a(  Receive data and return completed requests.

Args:
    timeout: Optional timeout in seconds for read operation

Returns:
    list: List of HTTP2Request objects for completed requests

Raises:
    HTTP2ConnectionError: On protocol or connection errors
    asyncio.TimeoutError: If timeout expires
NtimeoutzSocket read error: T
error_coderK   )r(   wait_forr$   readREAD_BUFFER_SIZEOSErrorIOErrorr   r6   r5   receive_datar   FlowControlErrorcloser   FLOW_CONTROL_ERRORr   strFrameTooLargeErrorFRAME_SIZE_ERRORInvalidSettingsValueErrorgetattrPROTOCOL_ERRORTooManyStreamsErrorREFUSED_STREAMProtocolError_handle_eventappendrD   )	r9   rI   dataer   rK   completed_requestseventrequests	   &&       r   rQ   !AsyncHTTP2Connection.receive_dataz   s_    		B"$--KK$$T%:%:;# 
 "[[--d.C.CDD DLI	-\\..t4F:  E((/G""))'2  %%'''!!o
 E! 	B&)<QC'@AA	B .. 	-**(I(I*JJJ$SV,,00 	-**(G(G*HHH$SV,,77 		- !L$7J%jjJj777jjN,I,IjJJJ$SV,,11 	-**(E(E*FFF$SV,,++ 	-**(E(E*FFF$SV,,	- 	(s%  K=AC8 C4C8 K=(C8 4C65C8 9K=	K=D 'K=(K=-K:.K=4C8 6C8 8D	DDK=K74#E1EE11K7K7	#G,F/-GK7K7&IH)I.H1/IK7K7 #JJJK74K75#K2KK22K77K=c                L   \        V\        P                  4      '       d   V P                  V4      # \        V\        P                  4      '       d   V P                  V4      # \        V\        P                  4      '       d   V P                  V4      # \        V\        P                  4      '       d   V P                  V4       R# \        V\        P                  4      '       d    R# \        V\        P                  4      '       d   V P                  V4       R# \        V\        P                  4      '       d    R# \        V\        P                  4      '       d   V P                  V4       R# \        V\        P                   4      '       d   V P#                  V4      # R# )zHandle a single h2 event.

Args:
    event: h2 event object

Returns:
    HTTP2Request if a request is complete, None otherwise
N)
isinstancer   RequestReceived_handle_request_receivedDataReceived_handle_data_receivedStreamEnded_handle_stream_endedStreamReset_handle_stream_resetWindowUpdatedPriorityUpdated_handle_priority_updatedSettingsAcknowledgedConnectionTerminated_handle_connection_terminatedTrailersReceived_handle_trailers_receivedr9   rc   s   &&r   r^   "AsyncHTTP2Connection._handle_event   sI    eZ77880077z6677--e44z5566,,U33z5566%%e,"  z7788  z99::))%0  z>>??  z>>??..u5
  z::;;11%88r   c                    VP                   pVP                  p\        W 4      pW@P                  V&   VP	                  VRR7       R# )z-Handle RequestReceived event (HEADERS frame).F
end_streamN)	stream_idheadersr   r'   receive_headers)r9   rc   r}   r~   streams   &&   r   ri   -AsyncHTTP2Connection._handle_request_received   sA    OO	-- Y-"(Y 	w59r   c                *   VP                   pVP                  pV P                  P                  V4      pVf   R# VP	                  VRR7       \        V4      ^ 8  dP    V P                  P                  \        V4      VR7       V P                  P                  \        V4      RR7       R# R#   \        \        P                  3 dJ    RT n         T P                  P                  \        P                  R7        R#   \         d      R# i ; ii ; i)zHandle DataReceived event.NFr{   )r}   TrJ   )r}   r`   r'   getrQ   lenr5   increment_flow_control_window
ValueErrorr   rR   r6   close_connectionr   rT   	Exception)r9   rc   r}   r`   r   s   &&   r   rk   *AsyncHTTP2Connection._handle_data_received   s    OO	zz!!),>DU3 t9q=::3t9PY:Z::3t9PT:U   ? ?@   $LL11^=^=^1_  ! s+   AB. ."D*C>>D	DDDc                   VP                   pV P                  P                  V4      pVf   R# RVn        RVn        VP
                  '       d   VP
                  P                  4        \        W0P                  V P                  4      # )zHandle StreamEnded event.NT)
r}   r'   r   request_complete_body_complete_body_eventsetr   r#   r&   r9   rc   r}   r   s   &&  r   rm   )AsyncHTTP2Connection._handle_stream_ended  sn    OO	!!),>
 #' $""$FHHd.>.>??r   c                    VP                   pV P                  P                  V4      pVe   VP                  VP                  4       R# R# )zHandle StreamReset event.N)r}   r'   r   resetrK   r   s   &&  r   ro   )AsyncHTTP2Connection._handle_stream_reset#  s<    OO	!!),LL))* r   c                    RV n         R# )z"Handle ConnectionTerminated event.TNr6   rx   s   &&r   ru   2AsyncHTTP2Connection._handle_connection_terminated+  s	    r   c                    VP                   pV P                  P                  V4      pVf   R# VP                  VP                  4       \        W0P                  V P                  4      # )zHandle TrailersReceived event.N)r}   r'   r   receive_trailersr~   r   r#   r&   r   s   &&  r   rw   .AsyncHTTP2Connection._handle_trailers_received/  sP    OO	!!),>.FHHd.>.>??r   c                    V P                   P                  VP                  4      pVe5   VP                  VP                  VP
                  VP                  R7       R# R# )zjHandle PriorityUpdated event (PRIORITY frame).

Args:
    event: PriorityUpdated event with priority info
N)weight
depends_on	exclusive)r'   r   r}   update_priorityr   r   r   )r9   rc   r   s   && r   rr   -AsyncHTTP2Connection._handle_priority_updated:  sQ     !!%//2""|| ++// #  r   c                  "   V^d8  g   V^8  d   \        RV 24      hV P                  P                  V4      pVf   \        RV R24      hR\        V4      3.pV F/  w  rgVP	                  VP                  4       \        V4      34       K1  	  V P                  P                  WRR7       V P                  4       G Rj  xL
  R#  L5i)av  Send an informational response (1xx) on a stream.

This is used for 103 Early Hints and other 1xx responses.
Informational responses are sent before the final response
and do not end the stream.

Args:
    stream_id: The stream ID
    status: HTTP status code (100-199)
    headers: List of (name, value) header tuples

Raises:
    HTTP2Error: If status is not in 1xx range
zInvalid informational status: NzStream z
 not found:statusFr{   )	r   r'   r   rU   r_   lowerr5   send_headersrD   )r9   r}   statusr~   r   response_headersnamevalues   &&&&    r   send_informational'AsyncHTTP2Connection.send_informationalH  s      C<6S==fXFGG!!),>wyk<== 'F45"KD##TZZ\3u:$>? #
 	!!)%!P%%'''s   B>C	 CC	c                  "   V P                   P                  V4      pVf   R# R\        V4      3.pV F/  w  rxVP                  VP	                  4       \        V4      34       K1  	  VRJ ;'       g    \        V4      ^ 8H  p	 V P                  P                  WV	R7       VP                  WiR7       V P                  4       G Rj  xL
  V'       d,   \        V4      ^ 8  d   V P                  WRR7      G Rj  xL
  R#  L9 L  \        P                   d&    TP                  4        T P                  T4        R# i ; i5i)a  Send a response on a stream.

Args:
    stream_id: The stream ID to respond on
    status: HTTP status code (int)
    headers: List of (name, value) header tuples
    body: Optional response body bytes

Returns:
    bool: True if response sent, False if stream was already closed
NFr   r{   T)r'   r   rU   r_   r   r   r5   r   rD   	send_datar   StreamClosedErrorrS   cleanup_stream)
r9   r}   r   r~   bodyr   r   r   r   r|   s
   &&&&&     r   send_response"AsyncHTTP2Connection.send_responseh  s     !!),> 'F45"KD##TZZ\3u:$>? # T\33SY!^
	LL%%ij%Y 0H))+++ D	AnnYnFFF , G// 	LLN	*		s[   A/D?2D?AD C>D &D 7D 8D <D?>D  D 6D<8D?;D<<D?c                   "   ^2p\        V4       EF#  pV P                  P                  V4      pV^ 8  d   Vu #  \        P                  ! V P
                  P                  V P                  4      RR7      G Rj  xL
 pV'       d   V P                  P                  V4      pV Fi  p\        V\        P                  4      '       d   VP                  V8X  d   Ru u # K<  \        V\        P                  4      '       g   K^  RV n        Ru u # 	  V P                  4       G Rj  xL
  EK  RV n        Ru # 	  V P                  P                  V4      #  L L1  \        P                    d     EK`  \"        P$                   d    Ru u # i ; i5i)zsWait for flow control window to become positive.

Returns:
    int: Available window size, or -1 if waiting failed
g?rH   NT)ranger5   local_flow_control_windowr(   rL   r$   rM   rN   rQ   rg   r   rn   r}   rt   r6   rD   TimeoutErrorr   r]   )r9   r}   max_wait_attempts_	availableincomingr   rc   s   &&      r   _wait_for_flow_control_window2AsyncHTTP2Connection._wait_for_flow_control_window  sM     ()A>>yII1}  !(!1!1KK$$T%:%:;"  !\\66x@F!'%eZ-C-CDD$);')	  <'z/N/NOO+/DL#%I "( 11333 $(DLI3 *> ||55i@@1 4
 '' !// 	s   8F>E9E:EAEFE
EFE#E$E(F+E3 FEEF,F0FFF
FFc                  "   V P                   P                  V4      pVf   R# Tp V'       d   V P                  P                  V4      p\	        W`P
                  \        V4      4      pV^ 8:  dZ   V P                  4       G Rj  xL
  V P                  V4      G Rj  xL
 pV^ 8:  d   R# \	        W`P
                  \        V4      4      pVRV pWWR pT;'       d    \        V4      ^ 8H  p	V P                  P                  WV	R7       V P                  4       G Rj  xL
  K  VP                  W#R7       R#  L L L  \        P                  \        P                  3 d&    TP                  4        T P                  T4        R# i ; i5i)zSend data on a stream.

Args:
    stream_id: The stream ID
    data: Body data bytes
    end_stream: Whether this ends the stream

Returns:
    bool: True if data sent, False if stream was already closed
NFr{   T)r'   r   r5   r   minr0   r   rD   r   r   r   r   rR   rS   r   )
r9   r}   r`   r|   r   data_to_sendr   
chunk_sizechunkis_finals
   &&&&      r   r   AsyncHTTP2Connection.send_data  sZ     !!),>	 LLBB9M	 ,?,?\ARS
?11333&*&H&H&S SI A~$!$Y0C0CSEV!WJ$[j1+K8%@@#l*;q*@&&yH&M--///T9 4 S 0 00.2Q2QR 	LLN	*	sw   $FD; AD; D5D; D7D; (F*0D; ?D; D9D; 3F5D; 7D; 9D; ;AFFFFc                B  "   V P                   P                  V4      pVf   R# VP                  '       g   R# . pV FW  w  rVVP                  4       pVP	                  R4      '       d   \        RV R24      hVP                  V\        V4      34       KY  	   V P                  P                  WRR7       VP                  V4       V P                  4       G Rj  xL
  R#  L  \        P                   d&    TP                  4        T P                  T4        R# i ; i5i)a  Send trailing headers on a stream.

Trailers are headers sent after the response body, commonly used
for gRPC status codes, checksums, and timing information.

Args:
    stream_id: The stream ID
    trailers: List of (name, value) trailer tuples

Raises:
    HTTP2Error: If stream not found, headers not sent, or pseudo-headers used

Returns:
    bool: True if trailers sent, False if stream was already closed
NF:zPseudo-header 'z' not allowed in trailersTr{   )r'   r   response_headers_sentr   
startswithr   r_   rU   r5   r   send_trailersrD   r   r   rS   r   )r9   r}   trailersr   trailer_headersr   r   lnames   &&&     r   r   "AsyncHTTP2Connection.send_trailers  s       !!),>+++ #KDJJLE$$ ?4&8Q!RSS""E3u:#67	 $
	LL%%iT%R  1))+++ ,// 	LLN	*		sB   3DA!DAC" C C" D C" "6DDDDc                   "   V'       d   VP                  4       MRpR\        \        V4      4      3.pV'       d   VP                  R4       V P	                  WWT4      G Rj  xL
  R#  L5i)z#Send an error response on a stream.r   zcontent-lengthN)zcontent-typeztext/plain; charset=utf-8)encoderU   r   r_   r   )r9   r}   status_codemessager   r~   s   &&&&  r   
send_errorAsyncHTTP2Connection.send_error  sP     #*w~~$c#d)n56NNHI  GGG   A A+"A)#A+c                   "   V P                   P                  V4      pVe   VP                  V4       V P                  P	                  WR7       V P                  4       G Rj  xL
  R#  L5i)zReset a stream with RST_STREAM.NrJ   )r'   r   r   r5   reset_streamrD   )r9   r}   rK   r   s   &&& r   r   !AsyncHTTP2Connection.reset_stream  sR     !!),LL$!!)!C%%'''r   c                  "   V P                   '       d   R# RV n         Vf8   V P                  '       d$   \        V P                  P                  4       4      M^ p V P                  P                  VR7       V P                  4       G Rj  xL
   V P                  P                  4        V P                  P                  4       G Rj  xL
  R#  LC  \         d     LNi ; i L  \         d     R# i ; i5i)z,Close the connection gracefully with GOAWAY.NTrJ   )r6   r'   maxkeysr5   r   rD   r   r%   rS   wait_closed)r9   rK   last_stream_ids   &&&r   rS   AsyncHTTP2Connection.close!  s     <<<!9=S!2!2!451N	LL))Z)@))+++	KK++))+++ , 		
 , 		sp   1C4%C4/C 	C
C 7C" C C" C4C CC4CC4 C" "C1-C40C11C4c                2  "   V P                   P                  4       pV'       dA    V P                  P                  V4       V P                  P	                  4       G Rj  xL
  R# R#  L  \
        \        3 d   pRT n        \        RT 24      hRp?ii ; i5i)z,Send any pending data from h2 to the socket.NTzSocket write error: )	r5   r   r%   writedrainrO   rP   r6   r   )r9   r`   ra   s   &  r   rD   'AsyncHTTP2Connection._send_pending_data7  s     ||((*G!!$'kk'')))  *W% G#*-A!+EFFGs:   #B8A) A'A) #B'A) )B:BBBc                    V P                   # )zCheck if connection is closed.r   rE   s   &r   	is_closedAsyncHTTP2Connection.is_closedB  s     ||r   c                >    V P                   P                  VR4       R# )z-Remove a stream after processing is complete.N)r'   pop)r9   r}   s   &&r   r   #AsyncHTTP2Connection.cleanup_streamG  s    D)r   c                N    R \        V P                  4       RV P                   R2# )z<AsyncHTTP2Connection streams=z closed=>)r   r'   r6   rE   s   &r   __repr__AsyncHTTP2Connection.__repr__K  s0    4<<() *ll^1&	
r   )r6   r7   r8   r*   r#   r&   r5   r,   r.   r0   r2   r$   r'   r%   )N)F)   )    N) __name__
__module____qualname____firstlineno____doc__rN   r:   rC   rQ   r^   ri   rk   rm   ro   ru   rw   rr   r   r   r   r   r   r   r   rS   rD   propertyr   r   r   __static_attributes____classdictcell__)__classdict__s   @r   r   r   0   s      )"V!*F"P$L
::@$+	@(@&P&AP)V*XH(,	G  *
 
r   r   )r   r(   errorsr   r   r   r   r   r   r   rd   r   r
   r   r   r   r   r   r   __all__r   r   r   <module>r      sX        ! 

""`
 `
F "
"r   