
    AҐiX                     P    d Z ddlmZ ddlmZ  G d d      Z G d d      ZddgZy)	zV
HTTP/2 request wrapper.

Provides a Request-compatible interface for HTTP/2 streams.
    )BytesIO)split_request_uric                   @    e Zd ZdZd Zd
dZd
dZd
dZd Zd Z	d	 Z
y)	HTTP2BodyzBody wrapper for HTTP/2 request data.

    Provides a file-like interface to the request body,
    compatible with gunicorn's Body class expectations.
    c                 D    t        |      | _        t        |      | _        y)zfInitialize with body data.

        Args:
            data: bytes containing the request body
        N)r   _datalen_len)selfdatas     O/var/www/descvideos/venv/lib/python3.12/site-packages/gunicorn/http2/request.py__init__zHTTP2Body.__init__   s     T]
I	    Nc                 p    || j                   j                         S | j                   j                  |      S )zRead data from the body.

        Args:
            size: Number of bytes to read, or None for all remaining

        Returns:
            bytes: The requested data
        )r   readr   sizes     r   r   zHTTP2Body.read!   s-     <::??$$zzt$$r   c                 p    || j                   j                         S | j                   j                  |      S )zRead a line from the body.

        Args:
            size: Maximum bytes to read

        Returns:
            bytes: A line of data
        )r   readliner   s     r   r   zHTTP2Body.readline.   s1     <::&&((zz""4((r   c                 8    | j                   j                  |      S )zRead all lines from the body.

        Args:
            hint: Approximate byte count hint

        Returns:
            list: List of lines
        )r   	readlines)r   hints     r   r   zHTTP2Body.readlines;   s     zz##D))r   c                 ,    t        | j                        S )zIterate over lines in the body.)iterr   r   s    r   __iter__zHTTP2Body.__iter__F   s    DJJr   c                     | j                   S )zReturn the content length.)r
   r   s    r   __len__zHTTP2Body.__len__J   s    yyr   c                 8    | j                   j                          y)zClose the body stream.N)r   closer   s    r   r    zHTTP2Body.closeN   s    

r   )N)__name__
__module____qualname____doc__r   r   r   r   r   r   r     r   r   r   r      s*    %)	* r   r   c                   N    e Zd ZdZd Zd Zd Zd Zed        Z	ed        Z
d Zy	)
HTTP2RequestzHTTP/2 request wrapper compatible with gunicorn Request interface.

    Wraps an HTTP2Stream to provide the same interface as the HTTP/1.x
    Request class, allowing workers to handle HTTP/2 requests using
    existing code paths.
    c                    || _         || _        || _        || _        d| _        |j                         }|j                  dd      | _        |j                  dd      | _        |j                  dd      }|j                  dd	      }|| _	        	 t        |      }|j                  xs d| _        |j                  xs d| _        |j                  xs d| _        || _        g | _        |j#                         D ]0  \  }}	| j                   j%                  |j'                         |	f       2 |rI| j                   D 
cg c]  \  }
}|
d
k7  s|
|f c}}
| _        | j                   j%                  d
|f       g | _        |j(                  r4|j(                  D 	cg c]  \  }}	|j'                         |	f c}	}| _        |j+                         }t-        |      | _        d| _        d| _        |j4                  | _        d| _        |j:                  | _        |j<                  | _        y# t        $ r || _        d| _        d| _        Y mw xY wc c}}
w c c}	}w )zInitialize from an HTTP/2 stream.

        Args:
            stream: HTTP2Stream instance with received headers/body
            cfg: Gunicorn configuration object
            peer_addr: Client address tuple (host, port)
        )   r   z:methodGETz:schemehttpsz
:authority z:path/HOSTFN)streamcfg	peer_addrremote_addrversionget_pseudo_headersgetmethodschemeurir   pathqueryfragment
ValueError
_authorityheadersget_regular_headersappenduppertrailersget_request_bodyr   body
must_close_expected_100_continue	stream_id
req_numberproxy_protocol_infopriority_weightpriority_depends_on)r   r/   r0   r1   pseudo	authorityr9   partsnamevaluenv	body_datas                r   r   zHTTP2Request.__init__[   s%    "$  **,jjE2jjG4JJ|R0	zz'3' 	%d+E

(bDI*DJ!NN0bDM $ !557 	7KD%LLu 56	7 /3||Ktq!qF{QFKDLLL 34 ?? $*??D% u%DM ++-	i(	  &+# !** $(   &55#)#=#= [  	DIDJDM	$ Ls%   A
H$ :I	I	I$IIc                     d| _         y)z1Force the connection to close after this request.TNrE   r   s    r   force_closezHTTP2Request.force_close   s	    r   c                     | j                   ryy)zCheck if connection should close after this request.

        HTTP/2 connections are persistent by design, but we may still
        need to close if explicitly requested.

        Returns:
            bool: True if connection should close
        TFrU   r   s    r   should_closezHTTP2Request.should_close   s     ??r   c                 ^    |j                         }| j                  D ]  \  }}||k(  s|c S  y)zGet a header value by name.

        Args:
            name: Header name (case-insensitive)

        Returns:
            str: Header value, or None if not found
        N)rA   r>   )r   rO   h_nameh_values       r   
get_headerzHTTP2Request.get_header   s7     zz|#|| 	OFG~	 r   c                 `    | j                  d      }|	 t        |      S y# t        $ r Y yw xY w)zsGet the Content-Length header value.

        Returns:
            int: Content length, or None if not set
        zCONTENT-LENGTHN)r\   intr<   )r   cls     r   content_lengthzHTTP2Request.content_length   sB     __-.>2w   s   
! 	--c                 $    | j                  d      S )zoGet the Content-Type header value.

        Returns:
            str: Content type, or None if not set
        zCONTENT-TYPE)r\   r   s    r   content_typezHTTP2Request.content_type   s     ~..r   c                 j    d| j                    d| j                   d| j                  j                   dS )Nz<HTTP2Request method=z path=z stream_id=>)r6   r9   r/   rG   r   s    r   __repr__zHTTP2Request.__repr__   s?    kk] #II; ../q2	
r   N)r!   r"   r#   r$   r   rV   rX   r\   propertyr`   rb   re   r%   r   r   r'   r'   S   sJ    K>Z   / /
r   r'   N)r$   ior   gunicorn.utilr   r   r'   __all__r%   r   r   <module>rj      s6     +? ?DT
 T
n ;
'r   