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__/httpserver.cpython-36.opt-1.pyc
3

	��f]<�@sdZddlZddlZddlmZddlmZmZddlm	Z	ddlm
Z
ddlmZddlm
Z
dd	lmZddlZdd
lmZmZmZmZmZmZmZmZmZejr�ddlmZGd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@s�eZdZdZeedd�dd�Zdeeje	ej
gdffeeeee
efejfe
eeeeeeeee
dd�dd	�Zeeed
�dd��Zeeed
�d
d��Zdd
�dd�Zejedd�dd�Zeejej d�dd�Z!edd�dd�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.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`: simple single-process::

            server = HTTPServer(app)
            server.listen(8888)
            IOLoop.current().start()

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

    2. `~tornado.tcpserver.TCPServer.bind`/`~tornado.tcpserver.TCPServer.start`:
       simple multi-process::

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

       When using this interface, an `.IOLoop` must *not* be passed
       to the `HTTPServer` constructor.  `~.TCPServer.start` will always start
       the server on the default singleton `.IOLoop`.

    3. `~tornado.tcpserver.TCPServer.add_sockets`: advanced multi-process::

            sockets = tornado.netutil.bind_sockets(8888)
            tornado.process.fork_processes(0)
            server = HTTPServer(app)
            server.add_sockets(sockets)
            IOLoop.current().start()

       The `~.TCPServer.add_sockets` interface is more complicated,
       but it can be used with `tornado.process.fork_processes` to
       give you more flexibility in when the fork happens.
       `~.TCPServer.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`.

    .. 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.
    N)�args�kwargs�returncOsdS)N�)�selfrrrr�"/usr/lib64/python3.6/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_downstreamrc	CsR||_||_||_t||||	p d||
|d�|_tj||||d�t�|_|
|_	dS)Ni)Z
decompressr"r#Zheader_timeoutr&r%r)rr'Zread_chunk_size)
rrr r�conn_paramsrr�set�_connectionsr()rrrrrr r!r"r#r$r%r&r'r(rrr�
initialize�s$
zHTTPServer.initialize)rcCstS)N)r)�clsrrr�configurable_base�szHTTPServer.configurable_basecCstS)N)r)r-rrr�configurable_default�szHTTPServer.configurable_defaultc�s,x&|jr&tt|j��}|j�IdHqWdS)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 caled with ``await``.

        N)r+�next�iter�close)r�connrrr�close_all_connections�sz HTTPServer.close_all_connections)�stream�addressrcCs:t|||j|j�}t||j|�}|jj|�|j|�dS)N)�_HTTPRequestContextr r(rr)r+�addZ
start_serving)rr5r6�contextr3rrr�
handle_stream�s
zHTTPServer.handle_stream)�server_conn�request_connrcCs>t|jtj�r|jj||�}nt|j|�}|jr:t||�}|S)N)�
isinstancerr�HTTPServerConnectionDelegate�
start_request�_CallableAdapterr�
_ProxyAdapter)rr;r<�delegaterrrr?�s
zHTTPServer.start_request)r;rcCs|jjtjt|��dS)N)r+�remove�typing�castr)rr;rrr�on_close�szHTTPServer.on_close)FFNNFNNNNNNN)#�__name__�
__module__�__qualname__�__doc__rrr
rr>r
�HTTPServerRequest�boolr�str�sslZ
SSLContext�int�floatrr,�classmethodrr	r.r/r4r�IOStreamrr:�object�HTTPConnection�HTTPMessageDelegater?rFrrrrr.s0`H	rc@s�eZdZeejgdfejdd�dd�Zeej	ej
fejee
dd�dd�Zeee
dd�d	d
�Zdd�dd
�Zdd�dd�ZdS)r@N)rr<rcCs"||_||_d|_d|_g|_dS)N)�
connectionr�requestrB�_chunks)rrr<rrrr�s
z_CallableAdapter.__init__)�
start_line�headersrcCs"tj|jtjtj|�|d�|_dS)N)rVrYrZ)rrKrVrDrE�RequestStartLinerW)rrYrZrrr�headers_receiveds

z!_CallableAdapter.headers_received)�chunkrcCs|jj|�dS)N)rX�append)rr]rrr�
data_receivedsz_CallableAdapter.data_received)rcCs*dj|j�|j_|jj�|j|j�dS)N�)�joinrXrWZbodyZ_parse_bodyr)rrrr�finishs
z_CallableAdapter.finishcCs|`dS)N)rX)rrrr�on_connection_closesz$_CallableAdapter.on_connection_close)rGrHrIr
rrKrTrr
r[�ResponseStartLine�HTTPHeadersrrr\�bytesr_rbrcrrrrr@�s	r@c@s\eZdZd
ejeeeeedd�dd�Z	ed�dd�Z
ejdd�d	d
�Z
dd�dd�ZdS)r7N)r5r6r r(rcCs�||_|jdk	r|jj|_nd|_|jtjtjfkrH|dk	rH|d|_nd|_|rZ||_nt|t	j
�rnd|_nd|_|j|_|j|_t
|p�g�|_dS)Nrz0.0.0.0�https�http)r6�socketZfamily�address_family�AF_INET�AF_INET6�	remote_ipr r=rZSSLIOStream�_orig_remote_ip�_orig_protocolr*r()rr5r6r r(rrrrs 
z_HTTPRequestContext.__init__)rcCs<|jtjtjfkr|jSt|jt�r.t|j�St	|j�SdS)N)
rjrirkrlrmr=r6rfrrM)rrrr�__str__As

z_HTTPRequestContext.__str__)rZrcCs�|jd|j�}x,dd�t|jd��D�D]}||jkr(Pq(W|jd|�}tj|�rX||_|jd|jd|j��}|r�|jd�dj�}|d
kr�||_dS)z2Rewrite the ``remote_ip`` and ``protocol`` fields.zX-Forwarded-Forcss|]}|j�VqdS)N)�strip)�.0Zcandrrr�	<genexpr>Qsz6_HTTPRequestContext._apply_xheaders.<locals>.<genexpr>�,z	X-Real-IpzX-SchemezX-Forwarded-Proto�rhrgN���)rhrg)	�getrm�reversed�splitr(rZis_valid_ipr rq)rrZZipZproto_headerrrr�_apply_xheadersLs

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)rnrmror )rrrr�_unapply_xheadersbsz%_HTTPRequestContext._unapply_xheaders)N)rGrHrIrrRrrrMrrrprrerzr{rrrrr7s
r7c@s�eZdZejejdd�dd�Zeejej	fej
eedd�dd�Z
eeedd�d	d
�Zdd�dd
�Zdd�dd�Zdd�dd�ZdS)rAN)rBr<rcCs||_||_dS)N)rVrB)rrBr<rrrrmsz_ProxyAdapter.__init__)rYrZrcCs|jjj|�|jj||�S)N)rVr9rzrBr\)rrYrZrrrr\usz_ProxyAdapter.headers_received)r]rcCs|jj|�S)N)rBr_)rr]rrrr_sz_ProxyAdapter.data_received)rcCs|jj�|j�dS)N)rBrb�_cleanup)rrrrrb�s
z_ProxyAdapter.finishcCs|jj�|j�dS)N)rBrcr|)rrrrrc�s
z!_ProxyAdapter.on_connection_closecCs|jjj�dS)N)rVr9r{)rrrrr|�sz_ProxyAdapter._cleanup)rGrHrIrrUrTrr
r[rdrerrr\rfr_rbrcr|rrrrrAlsrA)%rJrirNZtornado.escaperZtornado.http1connectionrrZtornadorrrZtornado.tcpserverrZtornado.utilr	rDr
rrr
rrrrrZ
TYPE_CHECKINGrr>rrUr@rSr7rArKZHTTPRequestrrrr�<module>s&,K&N"