HEX
Server: LiteSpeed
System: Linux php-prod-1.spaceapp.ru 5.15.0-157-generic #167-Ubuntu SMP Wed Sep 17 21:35:53 UTC 2025 x86_64
User: xnsbb3110 (1041)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/local/CyberPanel/lib/python3.10/site-packages/tornado/__pycache__/httpserver.cpython-310.pyc
o

��h	?�@sdZddlZddlZddlmZddlmZmZddlm	Z	ddlm
Z
ddlmZddlm
Z
dd	lmZddlZdd
lmZmZmZmZmZmZmZmZmZejrYddlmZGdd
�d
e
ee	j�ZGdd�de	j�ZGdd�de �Z!Gdd�de	j�Z"e	j#Z$dS)a�A non-blocking, single-threaded HTTP server.

Typical applications have little direct interaction with the `HTTPServer`
class except to start a server at the beginning of the process
(and even that is often done indirectly via `tornado.web.Application.listen`).

.. versionchanged:: 4.0

   The ``HTTPRequest`` class that used to live in this module has been moved
   to `tornado.httputil.HTTPServerRequest`.  The old name remains as an alias.
�N)�
native_str)�HTTP1ServerConnection�HTTP1ConnectionParameters)�httputil)�iostream)�netutil)�	TCPServer)�Configurable)	�Union�Any�Dict�Callable�List�Type�Tuple�Optional�	Awaitable)�Setc@sLeZdZdZdededdfdd�Z												d(d	eeje	ej
gdffd
ededeee
eefejfd
eededeedeedeedeedeedeedeeeddfdd�Zedeefdd��Zedeefdd��Zd)dd�Zdejdeddfd d!�Zd"ed#ej dej!fd$d%�Z"d"eddfd&d'�Z#dS)*�
HTTPServera�A non-blocking, single-threaded HTTP server.

    A server is defined by a subclass of `.HTTPServerConnectionDelegate`,
    or, for backwards compatibility, a callback that takes an
    `.HTTPServerRequest` as an argument. The delegate is usually a
    `tornado.web.Application`.

    `HTTPServer` supports keep-alive connections by default
    (automatically for HTTP/1.1, or for HTTP/1.0 when the client
    requests ``Connection: keep-alive``).

    If ``xheaders`` is ``True``, we support the
    ``X-Real-Ip``/``X-Forwarded-For`` and
    ``X-Scheme``/``X-Forwarded-Proto`` headers, which override the
    remote IP and URI scheme/protocol for all requests.  These headers
    are useful when running Tornado behind a reverse proxy or load
    balancer.  The ``protocol`` argument can also be set to ``https``
    if Tornado is run behind an SSL-decoding proxy that does not set one of
    the supported ``xheaders``.

    By default, when parsing the ``X-Forwarded-For`` header, Tornado will
    select the last (i.e., the closest) address on the list of hosts as the
    remote host IP address.  To select the next server in the chain, a list of
    trusted downstream hosts may be passed as the ``trusted_downstream``
    argument.  These hosts will be skipped when parsing the ``X-Forwarded-For``
    header.

    To make this server serve SSL traffic, send the ``ssl_options`` keyword
    argument with an `ssl.SSLContext` object. For compatibility with older
    versions of Python ``ssl_options`` may also be a dictionary of keyword
    arguments for the `ssl.SSLContext.wrap_socket` method.::

       ssl_ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
       ssl_ctx.load_cert_chain(os.path.join(data_dir, "mydomain.crt"),
                               os.path.join(data_dir, "mydomain.key"))
       HTTPServer(application, ssl_options=ssl_ctx)

    `HTTPServer` initialization follows one of three patterns (the
    initialization methods are defined on `tornado.tcpserver.TCPServer`):

    1. `~tornado.tcpserver.TCPServer.listen`: single-process::

            async def main():
                server = HTTPServer()
                server.listen(8888)
                await asyncio.Event.wait()

            asyncio.run(main())

       In many cases, `tornado.web.Application.listen` can be used to avoid
       the need to explicitly create the `HTTPServer`.

       While this example does not create multiple processes on its own, when
       the ``reuse_port=True`` argument is passed to ``listen()`` you can run
       the program multiple times to create a multi-process service.

    2. `~tornado.tcpserver.TCPServer.add_sockets`: multi-process::

            sockets = bind_sockets(8888)
            tornado.process.fork_processes(0)
            async def post_fork_main():
                server = HTTPServer()
                server.add_sockets(sockets)
                await asyncio.Event().wait()
            asyncio.run(post_fork_main())

       The ``add_sockets`` interface is more complicated, but it can be used with
       `tornado.process.fork_processes` to run a multi-process service with all
       worker processes forked from a single parent.  ``add_sockets`` can also be
       used in single-process servers if you want to create your listening
       sockets in some way other than `~tornado.netutil.bind_sockets`.

       Note that when using this pattern, nothing that touches the event loop
       can be run before ``fork_processes``.

    3. `~tornado.tcpserver.TCPServer.bind`/`~tornado.tcpserver.TCPServer.start`:
       simple **deprecated** multi-process::

            server = HTTPServer()
            server.bind(8888)
            server.start(0)  # Forks multiple sub-processes
            IOLoop.current().start()

       This pattern is deprecated because it requires interfaces in the
       `asyncio` module that have been deprecated since Python 3.10. Support for
       creating multiple processes in the ``start`` method will be removed in a
       future version of Tornado.

    .. versionchanged:: 4.0
       Added ``decompress_request``, ``chunk_size``, ``max_header_size``,
       ``idle_connection_timeout``, ``body_timeout``, ``max_body_size``
       arguments.  Added support for `.HTTPServerConnectionDelegate`
       instances as ``request_callback``.

    .. versionchanged:: 4.1
       `.HTTPServerConnectionDelegate.start_request` is now called with
       two arguments ``(server_conn, request_conn)`` (in accordance with the
       documentation) instead of one ``(request_conn)``.

    .. versionchanged:: 4.2
       `HTTPServer` is now a subclass of `tornado.util.Configurable`.

    .. versionchanged:: 4.5
       Added the ``trusted_downstream`` argument.

    .. versionchanged:: 5.0
       The ``io_loop`` argument has been removed.
    �args�kwargs�returnNcOsdS�N�)�selfrrrr�H/usr/local/CyberPanel/lib/python3.10/site-packages/tornado/httpserver.py�__init__�szHTTPServer.__init__F�request_callback�
no_keep_alive�xheaders�ssl_options�protocol�decompress_request�
chunk_size�max_header_size�idle_connection_timeout�body_timeout�
max_body_size�max_buffer_size�trusted_downstreamc	CsR||_||_||_t||||	pd||
|d�|_tj||||d�t�|_|
|_	dS)Ni)�
decompressr#r$�header_timeoutr'r&r)r r(�read_chunk_size)
rrr!r�conn_paramsrr�set�_connectionsr))rrrrr r!r"r#r$r%r&r'r(r)rrr�
initialize�s(�	�
zHTTPServer.initializecC�tSr�r��clsrrr�configurable_base��zHTTPServer.configurable_basecCr1rr2r3rrr�configurable_default�r6zHTTPServer.configurable_defaultc�s2�|jrtt|j��}|��IdH|jsdSdS)a&Close all open connections and asynchronously wait for them to finish.

        This method is used in combination with `~.TCPServer.stop` to
        support clean shutdowns (especially for unittests). Typical
        usage would call ``stop()`` first to stop accepting new
        connections, then ``await close_all_connections()`` to wait for
        existing connections to finish.

        This method does not currently close open websocket connections.

        Note that this method is a coroutine and must be called with ``await``.

        N)r/�next�iter�close)r�connrrr�close_all_connections�s
��z HTTPServer.close_all_connections�stream�addresscCs:t|||j|j�}t||j|�}|j�|�|�|�dSr)�_HTTPRequestContextr!r)rr-r/�add�
start_serving)rr=r>�contextr;rrr�
handle_stream�s�zHTTPServer.handle_stream�server_conn�request_conncCs>t|jtj�r|j�||�}nt|j|�}|jrt||�}|Sr)�
isinstancerr�HTTPServerConnectionDelegate�
start_request�_CallableAdapterr�
_ProxyAdapter)rrDrE�delegaterrrrH�s
zHTTPServer.start_requestcCs|j�t�t|��dSr)r/�remove�typing�castr)rrDrrr�on_closeszHTTPServer.on_close)FFNNFNNNNNNN�rN)$�__name__�
__module__�__qualname__�__doc__rrr
rrGr
�HTTPServerRequest�boolrr�str�ssl�
SSLContext�int�floatrr0�classmethodrr	r5r7r<r�IOStreamrrC�object�HTTPConnection�HTTPMessageDelegaterHrOrrrrr.s|m�������	�
���
����
�
�,
��
�
rc@s�eZdZdeejgdfdejddfdd�Zdeej	ej
fdejdee
dfd	d
�Zdedee
dfdd
�Zddd�Zddd�ZdS)rIrNrErcCs"||_||_d|_d|_g|_dSr)�
connectionr�requestrK�_chunks)rrrErrrrs

z_CallableAdapter.__init__�
start_line�headerscCs"tj|jt�tj|�|d�|_dS)N)rardre)rrUrarMrN�RequestStartLinerb�rrdrerrr�headers_receiveds�z!_CallableAdapter.headers_received�chunkcCs|j�|�dSr)rc�append�rrirrr�
data_receivedsz_CallableAdapter.data_receivedcCs8|jdusJ�d�|j�|j_|j��|�|j�dS)N�)rb�joinrc�body�_parse_bodyr�rrrr�finish s
z_CallableAdapter.finishcCs|`dSr)rcrqrrr�on_connection_close&sz$_CallableAdapter.on_connection_closerP)rQrRrSr
rrUr_rr
rf�ResponseStartLine�HTTPHeadersrrrh�bytesrlrrrsrrrrrIs$��
���

�
rIc@sheZdZ	ddejdedeedeeeddf
dd�Z	defd	d
�Z
dejddfdd
�Z
ddd�ZdS)r?Nr=r>r!r)rcCs�||_|jdur|jj|_nd|_|jtjtjfvr$|dur$|d|_nd|_|r-||_n
t|t	j
�r7d|_nd|_|j|_|j|_t
|pFg�|_dS)Nrz0.0.0.0�https�http)r>�socket�family�address_family�AF_INET�AF_INET6�	remote_ipr!rFr�SSLIOStream�_orig_remote_ip�_orig_protocolr.r))rr=r>r!r)rrrr+s 
z_HTTPRequestContext.__init__cCs8|jtjtjfvr|jSt|jt�rt|j�St	|j�Sr)
r{ryr|r}r~rFr>rvrrWrqrrr�__str__Ms


z_HTTPRequestContext.__str__recCs�|�d|j�}dd�t|�d��D�D]	}||jvrnq|�d|�}t�|�r+||_|�d|�d|j��}|rA|�d�d��}|d	vrJ||_d
Sd
S)z2Rewrite the ``remote_ip`` and ``protocol`` fields.zX-Forwarded-Forcss�|]}|��VqdSr)�strip)�.0�candrrr�	<genexpr>]s�z6_HTTPRequestContext._apply_xheaders.<locals>.<genexpr>�,z	X-Real-IpzX-SchemezX-Forwarded-Proto���)rxrwN)	�getr~�reversed�splitr)r�is_valid_ipr!r�)rre�ip�proto_headerrrr�_apply_xheadersXs 
�
�
�z#_HTTPRequestContext._apply_xheaderscCs|j|_|j|_dS)z�Undo changes from `_apply_xheaders`.

        Xheaders are per-request so they should not leak to the next
        request on the same connection.
        N)r�r~r�r!rqrrr�_unapply_xheadersnsz%_HTTPRequestContext._unapply_xheadersrrP)rQrRrSrr]rrrWrrr�rrur�r�rrrrr?*s ����
�
�"r?c@s�eZdZdejdejddfdd�Zdeejej	fdej
deedfd	d
�Z
dedeedfdd
�Zddd�Zddd�Zddd�ZdS)rJrKrErNcCs||_||_dSr)rarK)rrKrErrrrys
z_ProxyAdapter.__init__rdrecCs|jj�|�|j�||�Sr)rarBr�rKrhrgrrrrh�sz_ProxyAdapter.headers_receivedricCs|j�|�Sr)rKrlrkrrrrl�sz_ProxyAdapter.data_receivedcC�|j��|��dSr)rKrr�_cleanuprqrrrrr��
z_ProxyAdapter.finishcCr�r)rKrsr�rqrrrrs�r�z!_ProxyAdapter.on_connection_closecCs|jj��dSr)rarBr�rqrrrr��sz_ProxyAdapter._cleanuprP)rQrRrSrr`r_rr
rfrtrurrrhrvrlrrrsr�rrrrrJxs&��
���

�


rJ)%rTryrX�tornado.escaper�tornado.http1connectionrr�tornadorrr�tornado.tcpserverr�tornado.utilr	rMr
rrr
rrrrr�
TYPE_CHECKINGrrGrr`rIr^r?rJrU�HTTPRequestrrrr�<module>s(,W&N
"