+
    jDX                     ~    R t ^ RIH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# )	zc
HTTP/2 server connection implementation.

Uses the hyper-h2 library for HTTP/2 protocol handling.
)BytesIO)
HTTP2ErrorHTTP2ProtocolErrorHTTP2ConnectionErrorHTTP2NotAvailableHTTP2ErrorCode)HTTP2Stream)HTTP2RequestNc                     \         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        N/var/www/idalgo/venv/lib/python3.14/site-packages/gunicorn/http2/connection.py
_import_h2r      s8     "#&&.* "!!"s	   , Ac                      a  ] tR t^/t 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# ) HTTP2ServerConnectionzHTTP/2 server-side connection handler.

Manages the HTTP/2 connection state and multiplexed streams.
This class wraps the h2 library and provides a higher-level
interface for gunicorn workers.
i   c                   \        4        Wn        W n        W0n        / V n        . 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        \'        4       V n        RV n        RV n        R# )zInitialize an HTTP/2 server connection.

Args:
    cfg: Gunicorn configuration object
    sock: SSL socket with completed handshake
    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sockclient_addrstreams_pending_requests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_connr   _read_buffer_closed_initialized)selfr$   r%   r&   r   s   &&&& r   __init__HTTP2ServerConnection.__init__:   s     		&  "$ $'#@#@ &)&F&F#!66$'$B$B! ++# , 
 ''v'6 $I !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        RV n         R# )z|Send initial HTTP/2 settings to client.

Should be called after the SSL handshake completes and
before processing any data.
NT)r6   r3   update_settingsr   SettingCodesMAX_CONCURRENT_STREAMSr,   INITIAL_WINDOW_SIZEr*   MAX_FRAME_SIZEr.   MAX_HEADER_LIST_SIZEr0   initiate_connection_send_pending_datar7   s   &r   rA   )HTTP2ServerConnection.initiate_connectione   s      	$$%%<<d>Y>Y%%994;S;S%%44d6I6I%%::D<U<U	&
 	 	((*! r   Nc                   Vf'    V P                   P                  V P                  4      pV'       g
   RV n        . #  V P                  P                  V4      p. pT F+  pT P1                  T4      pTf   K  TP3                  T4       K-  	  T P5                  4        T#   \        \        3 d   p\        RT 24      hRp?ii ; i  \        P                   d:   pT P                  \        P                  R7       \        \        T4      4      hRp?i\        P                    d:   pT P                  \        P"                  R7       \        \        T4      4      hRp?i\        P$                   d^   p\'        TRR4      pTe   T P                  TR7       M T P                  \        P(                  R7       \        \        T4      4      hRp?i\        P*                   d:   pT P                  \        P,                  R7       \        \        T4      4      hRp?i\        P.                   d:   pT P                  \        P(                  R7       \        \        T4      4      hRp?ii ; i)a	  Process received data and return completed requests.

Args:
    data: Optional bytes to process. If None, reads from socket.

Returns:
    list: List of HTTP2Request objects for completed requests

Raises:
    HTTP2ConnectionError: On protocol or connection errors
NzSocket read error: T
error_coderG   )r%   recvREAD_BUFFER_SIZEOSErrorIOErrorr   r5   r3   receive_datar   FlowControlErrorcloser   FLOW_CONTROL_ERRORr   strFrameTooLargeErrorFRAME_SIZE_ERRORInvalidSettingsValueErrorgetattrPROTOCOL_ERRORTooManyStreamsErrorREFUSED_STREAMProtocolError_handle_eventappendrB   )r7   dataer   rG   completed_requestseventrequests   &&      r   rL   "HTTP2ServerConnection.receive_dataz   s    <Fyy~~d&;&;< DLI	-\\..t4F:  E((/G""))'2  	!!!c W% F*-@+DEEF .. 	-JJ."C"CJD$SV,,00 	-JJ."A"AJB$SV,,77 		- !L$7J%

j
1

n&C&C
D$SV,,11 	-JJ."?"?J@$SV,,++ 	-JJ."?"?J@$SV,,	-sw   %B C C.B<<CI&4DI&$I&%4EI&0I&1AG		I& I&!4HI&,I&-4I!!I&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r7   r^   s   &&r   rY   #HTTP2ServerConnection._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# )zcHandle RequestReceived event (HEADERS frame).

Args:
    event: RequestReceived event with headers
F
end_streamN)	stream_idheadersr   r'   receive_headers)r7   r^   rx   ry   streams   &&   r   rd   .HTTP2ServerConnection._handle_request_received   sC     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  d`    V P                  P                  \        V4      VR7       V P                  P                  \        V4      RR7       V P                  4        R# R#   \        \        P                  3 d%    T P                  \        P                  R7        R# i ; i)zHandle DataReceived event.

Args:
    event: DataReceived event with body data

Returns:
    None (request completion handled by StreamEnded)
NFrv   )rx   rF   )rx   r[   r'   getrL   lenr3   increment_flow_control_windowrB   
ValueErrorr   rM   rN   r   rO   )r7   r^   rx   r[   r{   s   &&   r   rf   +HTTP2ServerConnection._handle_data_received   s     OO	zz!!),>DU3 t9q=	I::3t9PY:Z::3t9PT:U'')
 	  ? ?@ I

n&G&G
H	Is   AB> >;C=<C=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      # )zsHandle StreamEnded event.

Args:
    event: StreamEnded event

Returns:
    HTTP2Request for the completed request
NT)
rx   r'   r~   request_complete_body_complete_body_eventsetr	   r$   r&   r7   r^   rx   r{   s   &&  r   rh   *HTTP2ServerConnection._handle_stream_ended  sr     OO	!!),>
 #' $""$ FHHd.>.>??r   c                    VP                   pV P                  P                  V4      pVe   VP                  VP                  4       R# R# )zQHandle StreamReset event (RST_STREAM frame).

Args:
    event: StreamReset event
N)rx   r'   r~   resetrG   r   s   &&  r   rj   *HTTP2ServerConnection._handle_stream_reset/  s>     OO	!!),LL))* r   c                    RV n         R# )z_Handle ConnectionTerminated event (GOAWAY frame).

Args:
    event: ConnectionTerminated event
TNr5   rs   s   &&r   rp   3HTTP2ServerConnection._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      # )zHandle TrailersReceived event.

Args:
    event: TrailersReceived event with trailer headers

Returns:
    HTTP2Request if this completes the request
N)rx   r'   r~   receive_trailersry   r	   r$   r&   r   s   &&  r   rr   /HTTP2ServerConnection._handle_trailers_receivedE  sT     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~   rx   update_priorityr   r   r   )r7   r^   r{   s   && r   rm   .HTTP2ServerConnection._handle_priority_updatedY  sQ     !!%//2""|| ++// #  r   c                z   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        R# )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:statusFrv   )	r   r'   r~   rP   rZ   lowerr3   send_headersrB   )r7   rx   statusry   r{   response_headersnamevalues   &&&&    r   send_informational(HTTP2ServerConnection.send_informationalg  s     C<6S==fXFGG!!),>wyk<== 'F45"KD##TZZ\3u:$>? #
 	!!)%!P!r   c                R   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        V'       d$   \        V4      ^ 8  d   V P                  WRR7       R#   \        P                   d&    TP                  4        T P                  T4        R# i ; i)aY  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

Raises:
    HTTP2Error: If stream not found or in invalid state

Returns:
    bool: True if response sent, False if stream was already closed
NFr   rv   T)r'   r~   rP   rZ   r   r   r3   r   rB   	send_datar   StreamClosedErrorrN   cleanup_stream)
r7   rx   r   ry   bodyr{   r   r   r   rw   s
   &&&&&     r   send_response#HTTP2ServerConnection.send_response  s    !!),> 'F45"KD##TZZ\3u:$>? # T\33SY!^
	LL%%ij%Y 0H##% D	Ay4@// 	LLN	*		s    A*C, ,6D&%D&c                   ^ RI p^2p VP                  4       pVP                  V P                  VP                  4       Rp \        T4       EF  pT P                  P                  T4      pT^ 8  d   Tp EMTP                  RR7      pT'       g   KG   T P                  P                  T P                  4      p	T	'       g
   RT n         M T P                  P%                  T	4      p
T
 Fe  p\'        T\(        P*                  4      '       d   TP,                  T8X  d   Rp MDK:  \'        T\(        P.                  4      '       g   K\  RT n        Rp M	  T P1                  4        EK   M	  T P                  P                  T4      pTP3                  4        T#   \
        \        3 d    Ru # i ; i  \        \        \        P                   3 d      KO  i ; i  \        P                    d      Kl  i ; i  TP3                  4        i ; i)zsWait for flow control window to become positive.

Returns:
    int: Available window size, or -1 if waiting failed
Ng?)timeoutT)	selectorsDefaultSelectorregisterr%   
EVENT_READ	TypeErrorr   ranger3   local_flow_control_windowselectrH   rI   rJ   rK   r   rX   r5   rL   rb   r   ri   rx   ro   rB   rN   )r7   rx   r   max_wait_attemptsselresult_	availablereadyincomingr   r^   s   &&          r   _wait_for_flow_control_window3HTTP2ServerConnection._wait_for_flow_control_window  s    		++-CLLI$8$89
 %	,- LLBB9M	q=&F

3
/5#'99>>$2G2G#H $'+!%!:!:8!D "(%eZ-C-CDD$);)+ %  < (z/N/NOO+/DL%'F! "( //1 ? .D ??	JIIKY :& 	I	  $Wn.J.JK  *77 & IIKss   6F AG3 %F.9G3 	G3 G&AG3 ?G3 F+*F+. GG3 GG3 G0+G3 /G00G3 3H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:  dJ   V P                  4        V P                  V4      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        K  VP                  W#R7       R#   \        P                  \        P                  3 d&    TP                  4        T P                  T4        R# i ; 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
NFrv   T)r'   r~   r3   r   minr.   r   rB   r   r   r   r   rM   rN   r   )
r7   rx   r[   rw   r{   data_to_sendr   
chunk_sizechunkis_finals
   &&&&      r   r   HTTP2ServerConnection.send_data  s:    !!),>	 LLBB9M	 ,?,?\ARS
?++- $ B B9 MI A~$!$Y0C0CSEV!WJ$[j1+K8%@@#l*;q*@&&yH&M'')T900.2Q2QR 	LLN	*		s%   D A)D 0D 	AD AE%$E%c                &   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        R#   \        P                   d&    TP                  4        T P                  T4        R# i ; 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
F:zPseudo-header 'z' not allowed in trailersTrv   )r'   r~   response_headers_sentr   
startswithr   rZ   rP   r3   r   send_trailersrB   r   r   rN   r   )r7   rx   trailersr{   trailer_headersr   r   lnames   &&&     r   r   #HTTP2ServerConnection.send_trailers  s      !!),>+++ #KDJJLE$$ ?4&8Q!RSS""E3u:#67	 $
	LL%%iT%R  1##%// 	LLN	*		s   >C 6D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       R# )zSend an error response on a stream.

Args:
    stream_id: The stream ID
    status_code: HTTP status code
    message: Optional error message body
r   zcontent-lengthN)zcontent-typeztext/plain; charset=utf-8)encoderP   r   rZ   r   )r7   rx   status_codemessager   ry   s   &&&&  r   
send_error HTTP2ServerConnection.send_errorE  sI     $+w~~$c#d)n56NNHI97Ar   c                    V P                   P                  V4      pVe   VP                  V4       V P                  P	                  WR7       V P                  4        R# )zReset a stream with RST_STREAM.

Args:
    stream_id: The stream ID to reset
    error_code: HTTP/2 error code (default: CANCEL)
NrF   )r'   r~   r   r3   reset_streamrB   )r7   rx   rG   r{   s   &&& r   r   "HTTP2ServerConnection.reset_streamT  sK     !!),LL$!!)!C!r   c                0   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        R#   \         d     R# i ; i)zClose the connection gracefully with GOAWAY.

Args:
    error_code: HTTP/2 error code (default: NO_ERROR)
    last_stream_id: Last processed stream ID (default: highest)
NTrF   )r5   r'   maxkeysr3   close_connectionrB   	Exception)r7   rG   last_stream_ids   &&&r   rN   HTTP2ServerConnection.closeb  sv     <<<!9=S!2!2!451N	LL))Z)@##% 		s   ,B BBc                    V P                   P                  4       pV'       d    V P                  P                  V4       R# R#   \        \
        3 d   pRT n        \        RT 24      hRp?ii ; i)z,Send any pending data from h2 to the socket.TzSocket write error: N)r3   r   r%   sendallrJ   rK   r5   r   )r7   r[   r\   s   &  r   rB   (HTTP2ServerConnection._send_pending_datax  sg    ||((*G		!!$'  W% G#*-A!+EFFGs   A A.A))A.c                    V P                   # )zCheck if connection is closed.r   rC   s   &r   	is_closedHTTP2ServerConnection.is_closed  s     ||r   c                >    V P                   P                  VR4       R# )z^Remove a stream after processing is complete.

Args:
    stream_id: The stream ID to clean up
N)r'   pop)r7   rx   s   &&r   r   $HTTP2ServerConnection.cleanup_stream  s     	D)r   c                N    R \        V P                  4       RV P                   R2# )z<HTTP2ServerConnection streams=z closed=>)r   r'   r5   rC   s   &r   __repr__HTTP2ServerConnection.__repr__  s0    4<<() *ll^1&	
r   )r5   r6   r(   r4   r$   r&   r3   r*   r,   r.   r0   r%   r'   )N)F)   )    N) __name__
__module____qualname____firstlineno____doc__rI   r8   rA   rL   rY   rd   rf   rh   rj   rp   rr   rm   r   r   r   r   r   r   r   rN   rB   propertyr   r   r   __static_attributes____classdictcell__)__classdict__s   @r   r    r    /   s      )"V!*@"D$L:" D@4
+@("@*X8t*X*XB",G  *
 
r   r    )r   ior   errorsr   r   r   r   r   r{   r   r_   r	   r   r   r   r   r   r   r    __all__r   r   r   <module>r      sX        ! 

""e	
 e	
P #
#r   