BYPASS SHELL BY ./RAZORGANZ
Server: nginx/1.20.1
System: Linux iZdzfnv9mwfppeZ 5.10.134-19.2.al8.x86_64 #1 SMP Wed Oct 29 22:47:09 CST 2025 x86_64
User: apache (48)
PHP: 8.2.30
Disabled: NONE
Upload Files
File: //lib64/python3.6/site-packages/tornado/__pycache__/http1connection.cpython-36.pyc
3

	��fO��@sdZddlZddlZddlZddlZddlmZmZmZddl	m
Z
mZddlm
Z
ddlmZddlmZddlmZmZdd	lmZdd
lmZmZmZmZmZmZmZGdd�de�ZGd
d�de�Z Gdd�de�Z!Gdd�dej"�Z#Gdd�dej$�Z%Gdd�de�Z&dS)zFClient and server implementations of HTTP/1.x.

.. versionadded:: 4.0
�N)�Future�future_add_done_callback�"future_set_result_unless_cancelled)�
native_str�utf8)�gen)�httputil)�iostream)�gen_log�app_log)�GzipDecompressor)�cast�Optional�Type�	Awaitable�Callable�Union�Tuplec@seZdZdd�dd�ZdS)�_QuietExceptionN)�returncCsdS)N�)�selfrr�'/usr/lib64/python3.6/http1connection.py�__init__+sz_QuietException.__init__)�__name__�
__module__�__qualname__rrrrrr*src@sJeZdZdZejdd�dd�Zdd�dd�Zd	ee	e
jdd
�dd�ZdS)
�_ExceptionLoggingContextz�Used with the ``with`` statement when calling delegate methods to
    log any exceptions with the given logger.  Any exceptions caught are
    converted to _QuietException
    N)�loggerrcCs
||_dS)N)r)rrrrrr5sz!_ExceptionLoggingContext.__init__)rcCsdS)Nr)rrrr�	__enter__8sz"_ExceptionLoggingContext.__enter__zOptional[Type[BaseException]])�typ�value�tbrcCs2|dk	r.|dk	st�|jjd|||fd�t�dS)NzUncaught exception)�exc_info)�AssertionErrorr�errorr)rr r!r"rrr�__exit__;sz!_ExceptionLoggingContext.__exit__)
rrr�__doc__�loggingZLoggerrrr�
BaseException�types�
TracebackTyper&rrrrr/src
@s.eZdZdZdeeeeeeedd�dd�ZdS)�HTTP1ConnectionParameterszDParameters for `.HTTP1Connection` and `.HTTP1ServerConnection`.
    FN)�
no_keep_alive�
chunk_size�max_header_size�header_timeout�
max_body_size�body_timeout�
decompressrcCs6||_|pd|_|pd|_||_||_||_||_dS)a;
        :arg bool no_keep_alive: If true, always close the connection after
            one request.
        :arg int chunk_size: how much data to read into memory at once
        :arg int max_header_size:  maximum amount of data for HTTP headers
        :arg float header_timeout: how long to wait for all headers (seconds)
        :arg int max_body_size: maximum amount of data for body
        :arg float body_timeout: how long to wait while reading body (seconds)
        :arg bool decompress: if true, decode incoming
            ``Content-Encoding: gzip``
        iN)r-r.r/r0r1r2r3)rr-r.r/r0r1r2r3rrrrKs

z"HTTP1ConnectionParameters.__init__)FNNNNNF)rrrr'�bool�int�floatrrrrrr,Gsr,c@s�eZdZdZd>ejeeedd�dd�Z	e
jeed�dd�Z
e
jed�d	d
�Zdd�dd
�Zeegdfdd�dd�Zdd�dd�Zdd�dd�Zejd�dd�Zedd�dd�Zedd�dd�Zd?ee
je
jfe
jedd�dd �Zeed!�d"d#�Z edd!�d$d%�Z!dd�d&d'�Z"ddd(�d)d*�Z#e
je
jed+�d,d-�Z$d.dd(�d/d0�Z%ee&e'e
jfd1�d2d3�Z(ee
je
jeedd4�d5d6�Z)ee
jdd7�d8d9�Z*e
jdd�d:d;�Z+e
jdd�d<d=�Z,dS)@�HTTP1Connectionz�Implements the HTTP/1.x protocol.

    This class can be on its own for clients, or via `HTTP1ServerConnection`
    for servers.
    N)�stream�	is_client�params�contextrcCs�||_||_|dkrt�}||_||_|j|_|jjp<|jj|_|jj	|_
d|_d|_t
�|_d|_|j�d|_d|_d|_d|_d|_d|_dS)a
        :arg stream: an `.IOStream`
        :arg bool is_client: client or server
        :arg params: a `.HTTP1ConnectionParameters` instance or ``None``
        :arg context: an opaque application-defined object that can be accessed
            as ``connection.context``.
        NF)r9r8r,r:r;r-r1Zmax_buffer_size�_max_body_sizer2�
_body_timeout�_write_finished�_read_finishedr�_finish_future�_disconnect_on_finish�_clear_callbacks�_request_start_line�_response_start_line�_request_headers�_chunking_output�_expected_content_remaining�_pending_write)rr8r9r:r;rrrrps(
zHTTP1Connection.__init__)�delegatercCs |jjrt||jj�}|j|�S)azRead a single HTTP response.

        Typical client-mode usage is to write a request using `write_headers`,
        `write`, and `finish`, and then call ``read_response``.

        :arg delegate: a `.HTTPMessageDelegate`

        Returns a `.Future` that resolves to a bool after the full response has
        been read. The result is true if the stream is still open.
        )r:r3�_GzipMessageDelegater.�
_read_message)rrIrrr�
read_response�szHTTP1Connection.read_responsec4�s�d}�z��y"|jjd|jjd�}|jjdkr8|IdH}nLy,tj|jjj�|jj|t	j
d�IdH}Wntjk
r�|j�dSX|j
|�\}}|jr�tj|�}||_|}d|_n*tj|�}	|	|_||_|	}|j|	|�|_d}tt��&|j||�}
|
dk	�r|
IdHWdQRX|jdk�r*d}dSd}|j�r�t|tj��sHt�|jdk	�rf|jjdk�rfd}|j}|dk�rzd}|dk�r�|d	k�r�d
|k�s�d|k�r�tjd|��|j |�IdHn&|j!d
�dk�r�|j"�r�|jj#d�|�s�|j$|j�r|jnd||�}
|
dk	�r�|j%dk�r,|
IdHn\y*tj|jjj�|j%|
t	j
d�IdHWn0tjk
�r�t&j'd|j(�|jj�dSXd|_)|j"�s�|j�r�d}tt��|j*�WdQRX|j+j,��r|jdk	�r|jj-��r|jj.|j/�|j+IdH|j�r|j�r|j�|jdk�r*dSWnVtjk
�r�}z6t&j'd|j(|�|j�sl|jj#d�IdH|j�dSd}~XnXWd|�r�tt��|j0�WdQRXd}|j1�XdS)NFs
?

?
)�	max_bytes)Zquiet_exceptionsT�HEADi0�d��zContent-LengthzTransfer-Encodingz!Response code %d cannot have bodyZExpectz100-continuesHTTP/1.1 100 (Continue)

rzTimeout reading body from %sz"Malformed HTTP message from %s: %ssHTTP/1.1 400 Bad Request

)2r8Zread_until_regexr:r/r0rZwith_timeout�io_loopZtimer	�StreamClosedError�TimeoutError�close�_parse_headersr9rZparse_response_start_linerDrAZparse_request_start_linerCrE�_can_keep_aliverr�headers_received�
isinstance�ResponseStartLiner$�method�code�HTTPInputErrorrK�getr>�write�
_read_bodyr=r
�infor;r?�finishr@�done�closed�set_close_callback�_on_connection_close�on_connection_closerB)rrIZneed_delegate_closeZ
header_futureZheader_dataZstart_line_str�headersZresp_start_line�
start_lineZreq_start_lineZheader_recv_futureZ	skip_bodyr[Zbody_future�errrrK�s�










zHTTP1Connection._read_message)rcCs,d|_d|_d|_|jdk	r(|jjd�dS)z�Clears the callback attributes.

        This allows the request handler to be garbage collected more
        quickly in CPython by breaking up reference cycles.
        N)�_write_callback�
_write_future�_close_callbackr8rd)rrrrrB.s

z HTTP1Connection._clear_callbacks)�callbackrcCs
||_dS)a$Sets a callback that will be run when the connection is closed.

        Note that this callback is slightly different from
        `.HTTPMessageDelegate.on_connection_close`: The
        `.HTTPMessageDelegate` method is called when the connection is
        closed while recieving a message. This callback is used when
        there is not an active delegate (for example, on the server
        side this callback is used if the client closes the connection
        after sending its request but before receiving all the
        response.
        N)rl)rrmrrrrd:sz"HTTP1Connection.set_close_callbackcCs>|jdk	r|j}d|_|�|jj�s2t|jd�|j�dS)N)rlr@rbrrB)rrmrrrreHs

z$HTTP1Connection._on_connection_closecCs6|jdk	r|jj�|j�|jj�s2t|jd�dS)N)r8rTrBr@rbr)rrrrrTTs



zHTTP1Connection.closecCs.|j�|j}d|_|jj�s*t|jd�|S)a>Take control of the underlying stream.

        Returns the underlying `.IOStream` object and stops all further
        HTTP processing.  May only be called during
        `.HTTPMessageDelegate.headers_received`.  Intended for implementing
        protocols like websockets that tunnel over an HTTP handshake.
        N)rBr8r@rbr)rr8rrr�detach[s
zHTTP1Connection.detach)�timeoutrcCs
||_dS)ztSets the body timeout for a single request.

        Overrides the value from `.HTTP1ConnectionParameters`.
        N)r=)rrorrr�set_body_timeoutjsz HTTP1Connection.set_body_timeout)r1rcCs
||_dS)zwSets the body size limit for a single request.

        Overrides the value from `.HTTP1ConnectionParameters`.
        N)r<)rr1rrr�set_max_body_sizeqsz!HTTP1Connection.set_max_body_sizezFuture[None])rhrg�chunkrc	Csvg}|jrht|tj�st�||_|jtd|d|df��|jd kobd|kobd|kpb|dd	k|_	n�t|tj
�sxt�|jd
k	s�t�|jd
k	s�t�||_|jtd|d|df��|jj
d
ko�|jd!ko�|jdks�|jdko�d|ko�d|k|_	|jj
d
k�r|j�rd|d<|jj
dk�r@|jjdd�j�dk�r@d|d<|j	�rPd	|d<|j�r�|jjdk�s|ttj
|�jdk�r�d|_n d|k�r�t|d�|_nd
|_dd�|j�D�}|jdd�|D��x(|D] }d|k�r�tdt|����q�Wd
}|jj��r(t�}|_|jtj��|j �nJt�}|_dj!|�d}|�rV||j"|�7}|jj#|�|_$t%|j$|j&�|S)"z+Implements `.HTTPConnection.write_headers`.z%s %s HTTP/1.1r��POST�PUT�PATCHzContent-LengthzTransfer-Encoding�chunkedNzHTTP/1.1 %d %s�zHTTP/1.1���0rOrPrT�
ConnectionzHTTP/1.0�z
keep-alivez
Keep-AliverNcss&|]\}}t|�dt|�VqdS)z: N)r)�.0�n�vrrr�	<genexpr>�sz0HTTP1Connection.write_headers.<locals>.<genexpr>css|]}|jd�VqdS)�latin1N)�encode)r}�lrrrr��s�
zNewline in header: s
s

)rtrurv)ryrz)'r9rXr�RequestStartLiner$rC�appendrrZrFrYrErD�versionr[rAr]�lowerr
rGr5Zget_all�extend�
ValueError�reprr8rcrrk�
set_exceptionr	rR�	exception�join�
_format_chunkr^rHr�_on_write_complete)	rrhrgrr�linesZheader_lines�line�future�datarrr�
write_headersxsf







zHTTP1Connection.write_headers)rrrcCsh|jdk	r:|jt|�8_|jdkr:|jj�tjd��|jr`|r`tdt|��d|dS|SdS)Nrz,Tried to write more data than Content-Lengthz%xs
)rG�lenr8rTr�HTTPOutputErrorrFr)rrrrrrr��s



zHTTP1Connection._format_chunkcCshd}|jj�r6t�}|_|jjtj��|jj�n.t�}|_|jj|j	|��|_
t|j
|j�|S)z�Implements `.HTTPConnection.write`.

        For backwards compatibility it is allowed but deprecated to
        skip `write_headers` and instead call `write()` with a
        pre-encoded header block.
        N)
r8rcrrkr�r	rRr�r^r�rHrr�)rrrr�rrrr^�s
zHTTP1Connection.writecCs�|jdk	r:|jdkr:|jj�r:|jj�tjd|j��|jrf|jj�sf|jjd�|_|jj	|j
�d|_|jsxd|_
|jjd�|jdkr�|jd�nt|j|j�dS)z$Implements `.HTTPConnection.finish`.Nrz0Tried to write %d bytes less than Content-Lengths0

T)rGr8rcrTrr�rFr^rHZadd_done_callbackr�r>r?rA�set_nodelay�_finish_requestr)rrrrra�s$





zHTTP1Connection.finish)r�rcCsn|j�}|dk	r&t|tj�r&|j�|jdk	rJ|j}d|_|jjj|�|j	dk	rj|j	}d|_	t
|d�dS)N)r�rXr	rR�resultrjr8rQZadd_callbackrkr)rr��excrmrrrr�s

z"HTTP1Connection._on_write_complete)rhrgrcCsp|jjrdS|jd�}|dk	r&|j�}|jdkr8|dkSd|ksd|jdd�j�dksdt|d	d�d
krl|dkSdS)NFr{zHTTP/1.1rTzContent-LengthzTransfer-Encodingr|rwrZrN�GETz
keep-alive)rNr�)r:r-r]r�r��getattr)rrhrgZconnection_headerrrrrV"s

zHTTP1Connection._can_keep_alivezOptional[Future[None]]cCsH|j�|jr"|jr"|j�dS|jjd�|jj�sDt|jd�dS)NF)	rBr9rArTr8r�r@rbr)rr�rrrr�6s
zHTTP1Connection._finish_request)r�rcCsLt|jd��jd�}|jd�}|d|�jd�}tjj||d��}||fS)Nr�z
�
�
)r�decode�lstrip�find�rstripr�HTTPHeaders�parse)rr�Zdata_strZeolrhrgrrrrUAs

zHTTP1Connection._parse_headers)r[rgrIrcs8d|kr�d|krtjd��d|dkrjtjd|d��t�fdd��D��r^tjd|d���d	|d<yt|d�}Wn&tk
r�tjd
|d��YnXtt|�|jkr�tjd��nd}|dkr�d|ks�|dkr�tjd
|��d	}|dk	�r|j	||�S|j
dd�j�dk�r"|j|�S|j
�r4|j|�SdS)NzContent-LengthzTransfer-Encodingz7Response with both Transfer-Encoding and Content-Length�,z,\s*c3s|]}|�dkVqdS)rNr)r}�i)�piecesrrr�`sz-HTTP1Connection._read_body.<locals>.<genexpr>z$Multiple unequal Content-Lengths: %rrz*Only integer Content-Length is allowed: %szContent-Length too longryz*Response with code %d should not have bodyr|rw)Nr)rr\�re�split�anyr5r�r
r<�_read_fixed_bodyr]r��_read_chunked_bodyr9�_read_body_until_close)rr[rgrI�content_lengthr)r�rr_Ms@



zHTTP1Connection._read_body)r�rIrc	�s|xv|dkrv|jjt|jj|�dd�IdH}|t|�8}|jsD|jrtt	��"|j
|�}|dk	rj|IdHWdQRXqWdS)NrT)�partial)r8�
read_bytes�minr:r.r�r>r9rr�
data_received)rr�rI�body�retrrrr��s


z HTTP1Connection._read_fixed_bodyc		�sd}�x
|jjddd�IdH}t|j�d�}|dkr\|jjd�IdH}|dkrXtjd��dS||7}||jkrxtjd��|}xr|r�|jjt||j	j
�d	d
�IdH}|t|�8}|js�|j
r~tt��"|j|�}|dk	r�|IdHWdQRXq~W|jjd�IdH}|dkst�qWdS)Nrs
�@)rM�rxz%improperly terminated chunked requestzchunked body too largeT)r�)r8Z
read_untilr5�stripr�rr\r<r�r:r.r�r>r9rrr�r$)	rrIZ
total_sizeZ
chunk_len_strZ	chunk_lenZcrlfZ
bytes_to_readrrr�rrrr��s2



z"HTTP1Connection._read_chunked_bodyc	�sR|jj�IdH}|js|jrNtt��"|j|�}|dk	rD|IdHWdQRXdS)N)r8Zread_until_closer>r9rrr�)rrIr�r�rrrr��s

z&HTTP1Connection._read_body_until_close)NN)N)-rrrr'r	�IOStreamr4r,�objectrr�HTTPMessageDelegaterrLrKrBrrrdrerTrnr6rpr5rqrr�rYr��bytesr�r�r^rar�rVr�r�strrUr_r�r�r�rrrrr7is@/zV 6 r7c@sxeZdZdZejedd�dd�Zeej	ej
fejee
dd�dd�Zedd	�d
d�Zdd�d
d�Zdd�dd�ZdS)rJzIWraps an `HTTPMessageDelegate` to decode ``Content-Encoding: gzip``.
    N)rIr.rcCs||_||_d|_dS)N)�	_delegate�_chunk_size�
_decompressor)rrIr.rrrr�sz_GzipMessageDelegate.__init__)rhrgrcCs:|jd�dkr,t�|_|jd|d�|d=|jj||�S)NzContent-EncodingZgzipzX-Consumed-Content-Encoding)r]rr��addr�rW)rrhrgrrrrW�s
z%_GzipMessageDelegate.headers_received)rrrc�sr|jrP|}xb|rL|jj||j�}|rB|jj|�}|dk	rB|IdH|jj}qWn|jj|�}|dk	rn|IdHdS)N)r�r3r�r�r�Zunconsumed_tail)rrrZcompressed_dataZdecompressedr�rrrr��s

z"_GzipMessageDelegate.data_received)rcCs*|jdk	r |jj�}|r td��|jj�S)Nz9decompressor.flush returned data; possile truncated input)r��flushr�r�ra)r�tailrrrra�s

z_GzipMessageDelegate.finishcCs
|jj�S)N)r�rf)rrrrrf�sz(_GzipMessageDelegate.on_connection_close)rrrr'rr�r5rrr�rYr�rrrWr�r�rarfrrrrrJ�s
rJc@sZeZdZdZdejeedd�dd�Zdd�dd�Z	e
jdd	�d
d�Ze
jdd	�dd
�Z
dS)�HTTP1ServerConnectionzAn HTTP/1.x server.N)r8r:r;rcCs*||_|dkrt�}||_||_d|_dS)z�
        :arg stream: an `.IOStream`
        :arg params: a `.HTTP1ConnectionParameters` or None
        :arg context: an opaque application-defined object that is accessible
            as ``connection.context``
        N)r8r,r:r;�_serving_future)rr8r:r;rrrr�szHTTP1ServerConnection.__init__)rc�sB|jj�|jdk	st�y|jIdHWntk
r<YnXdS)zmCloses the connection.

        Returns a `.Future` that resolves after the serving loop has exited.
        N)r8rTr�r$�	Exception)rrrrrTs
zHTTP1ServerConnection.close)rIrcCs>t|tj�st�tj|j|��}||_|jj	j
|dd��dS)znStarts serving requests on this connection.

        :arg delegate: a `.HTTPServerConnectionDelegate`
        cSs|j�S)N)r�)�frrr�<lambda>'sz5HTTP1ServerConnection.start_serving.<locals>.<lambda>N)rXr�HTTPServerConnectionDelegater$rZconvert_yielded�_server_request_loopr�r8rQZ
add_future)rrIZfutrrr�
start_servingsz#HTTP1ServerConnection.start_servingc�s�z�x�t|jd|j|j�}|j||�}y|j|�IdH}Wnbtjtjt	j
fk
rXdStk
rr|j�dSt
k
r�tjddd�|j�dSX|s�dSt	jd�IdHqWWd|j|�XdS)NFzUncaught exceptionT)r#r)r7r8r:r;Z
start_requestrLr	rRZUnsatisfiableReadError�asyncioZCancelledErrorrrTr�r
r%ZsleepZon_close)rrIZconnZrequest_delegater�rrrr�)s,z*HTTP1ServerConnection._server_request_loop)NN)rrrr'r	r�r,r�rrTrr�r�r�rrrrr��s
r�)'r'r�r(r�r*Ztornado.concurrentrrrZtornado.escaperrZtornadorrr	Ztornado.logr
rZtornado.utilrZtypingr
rrrrrrr�rr�rr,ZHTTPConnectionr7r�rJr�rrrr�<module>s,$"Z;