ó
    Rì?g	?  ã                   ó‚  • S r SSKrSSKrSSKJr  SSKJrJr  SSKJ	r	  SSKJ
r
  SSKJr  SSKJr  SS	KJr  SSKrSS
KJrJrJrJrJrJrJrJrJr  \R4                  (       a  SSKJr   " S S\\\	R8                  5      r " S S\	R<                  5      r " S S\ 5      r! " S S\	R<                  5      r"\	RF                  r$g)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                   óî  • \ rS rSrSrS\S\SS4S jr            S!S\\R                  \
\R                  /S4   4   S	\S
\S\\\\\4   \R"                  4      S\\   S\S\\   S\\   S\\   S\\   S\\   S\\   S\\\      SS4S jjr\S\\   4S j5       r\S\\   4S j5       rS"S jrS\R:                  S\SS4S jrS\ S\RB                  S\RD                  4S jr#S\ SS4S jr$S r%g)#Ú
HTTPServeré.   a•  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ÚreturnNc                 ó   • g ©N© )Úselfr   r   s      Ú4/usr/lib/python3/dist-packages/tornado/httpserver.pyÚ__init__ÚHTTPServer.__init__œ   s   € ð 	ó    Ú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           
      óº   • Xl         X0l        XPl        [        UUUU	=(       d    SUU
US9U l        [
        R                  " U UUUS9  [        5       U l        XÐl	        g )Ni  )Ú
decompressr)   r*   Úheader_timeoutr-   r,   r$   )r&   r.   Úread_chunk_size)
r#   r%   r'   r   Úconn_paramsr	   r    ÚsetÚ_connectionsr/   )r   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   s                 r   Ú
initializeÚHTTPServer.initialize¤   si   € ð. !1ÔØ ŒØ ŒÜ4Ø)Ø!Ø+Ø2×:°dØ'Ø%Ø'ñ
ˆÔô 	×ÒØØ#Ø+Ø&ò		
ô  ›EˆÔØ"4Õr"   c                 ó   • [         $ r   ©r   ©Úclss    r   Úconfigurable_baseÚHTTPServer.configurable_baseÐ   ó   € äÐr"   c                 ó   • [         $ r   r:   r;   s    r   Úconfigurable_defaultÚHTTPServer.configurable_defaultÔ   r?   r"   c              ƒ   óÆ   #   • U R                   (       aJ  [        [        U R                   5      5      nUR                  5       I Sh  v•N   U R                   (       a  MI  gg N7f)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)r6   ÚnextÚiterÚclose)r   Úconns     r   Úclose_all_connectionsÚ HTTPServer.close_all_connectionsØ   sG   é € ð ××äœ˜T×.Ñ.Ó/Ó0ˆDØ—*‘*“,×Ðð ××Óñ ùs   ‚AA!ÁAÁA!ÁA!ÚstreamÚaddressc                 óÊ   • [        XU R                  U R                  5      n[        XR                  U5      nU R
                  R                  U5        UR                  U 5        g r   )Ú_HTTPRequestContextr'   r/   r   r4   r6   ÚaddÚstart_serving)r   rJ   rK   ÚcontextrG   s        r   Úhandle_streamÚHTTPServer.handle_streamë   sS   € Ü%Ø˜TŸ]™]¨D×,CÑ,Có
ˆô % V×-=Ñ-=¸wÓGˆØ×Ñ×Ñ˜dÔ#Ø×Ñ˜4Õ r"   Úserver_connÚrequest_connc                 óô   • [        U R                  [        R                  5      (       a  U R                  R	                  X5      nO[        U R                  U5      nU R                  (       a  [        X25      nU$ r   )Ú
isinstancer#   r   ÚHTTPServerConnectionDelegateÚstart_requestÚ_CallableAdapterr%   Ú_ProxyAdapter)r   rS   rT   Údelegates       r   rX   ÚHTTPServer.start_requestó   s[   € ô �d×+Ñ+¬X×-RÑ-R×SÑSØ×,Ñ,×:Ñ:¸;ÓU‰Hä'¨×(=Ñ(=¸|ÓLˆHà�=�=Ü$ XÓ<ˆHàˆr"   c                 ól   • U R                   R                  [        R                  " [        U5      5        g r   )r6   ÚremoveÚtypingÚcastr   )r   rS   s     r   Úon_closeÚHTTPServer.on_close   s"   € Ø×Ñ× Ñ ¤§¢Ô-BÀKÓ!PÕQr"   )r6   r4   r'   r#   r/   r%   )FFNNFNNNNNNN©r   N)&Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r    r   r   rW   r   ÚHTTPServerRequestÚboolr   r   ÚstrÚsslÚ
SSLContextÚintÚfloatr   r7   Úclassmethodr   r
   r=   rA   rH   r   ÚIOStreamr   rQ   ÚobjectÚHTTPConnectionÚHTTPMessageDelegaterX   ra   Ú__static_attributes__r   r"   r   r   r   .   sæ  † ñkðZ˜cð ¨Sð °Tô ð $ØØGKØ"&Ø#(Ø$(Ø)-Ø37Ø(,Ø'+Ø)-Ø26ñ#*5àØ×1Ñ1Ø�h×0Ñ0Ð1°4Ð7Ñ8ð:ñ
ð*5ð ð*5ð ð*5ð ˜e D¨¨c¨¡N°C·N±NÐ$BÑCÑDð*5ð ˜3‘-ð*5ð !ð*5ð ˜S‘Mð*5ð " #™ð*5ð "*¨%¡ð*5ð ˜u‘oð*5ð   ‘}ð*5ð  " #™ð!*5ð" % T¨#¡YÑ/ð#*5ð$ 
õ%*5ðX ð $ |Ñ"4ó ó ðð ð T¨,Ñ%7ó ó ðôð&! H×$5Ñ$5ð !Àð !È$ô !ðØ!ðØ19×1HÑ1Hðà	×	%Ñ	%ôðR Fð R¨t÷ Rr"   r   c                   óø   • \ rS rSrS\\R                  /S4   S\R                  SS4S jrS\	\R                  \R                  4   S\R                  S\\S      4S	 jrS
\S\\S      4S jrSS jrSS jrSrg)rY   i  r#   NrT   r   c                 óF   • X l         Xl        S U l        S U l        / U l        g r   )Ú
connectionr#   Úrequestr[   Ú_chunks)r   r#   rT   s      r   r    Ú_CallableAdapter.__init__  s$   € ð
 'ŒØ 0ÔØˆŒØˆŒØˆ�r"   Ú
start_lineÚheadersc                 ó”   • [         R                  " U R                  [        R                  " [         R
                  U5      US9U l        g )N)rx   r|   r}   )r   ri   rx   r_   r`   ÚRequestStartLinery   ©r   r|   r}   s      r   Úheaders_receivedÚ!_CallableAdapter.headers_received  s9   € ô
  ×1Ò1Ø—‘Ü—{’{¤8×#<Ñ#<¸jÓIØñ
ˆŒð
 r"   Úchunkc                 ó:   • U R                   R                  U5        g r   )rz   Úappend©r   rƒ   s     r   Údata_receivedÚ_CallableAdapter.data_received  s   € Ø�‰×Ñ˜EÔ"Ør"   c                 óà   • U R                   c   eSR                  U R                  5      U R                   l        U R                   R	                  5         U R                  U R                   5        g )Nr"   )ry   Újoinrz   ÚbodyÚ_parse_bodyr#   ©r   s    r   ÚfinishÚ_CallableAdapter.finish   sM   € Ø�|‰|Ñ'Ð'Ð'ØŸH™H T§\¡\Ó2ˆ�‰ÔØ�‰× Ñ Ô"Ø×Ñ˜dŸl™lÕ+r"   c                 ó   • U ? g r   )rz   r�   s    r   Úon_connection_closeÚ$_CallableAdapter.on_connection_close&  s   € Ø‰Lr"   )rz   rx   r[   ry   r#   rc   )rd   re   rf   rg   r   r   ri   rs   r    r   r   ÚResponseStartLineÚHTTPHeadersr   r   r�   Úbytesr‡   rŽ   r‘   ru   r   r"   r   rY   rY     s¨   † ð	à" H×$>Ñ$>Ð#?ÀÐ#EÑFð	ð ×-Ñ-ð	ð 
ô		ð
à˜(×3Ñ3°X×5OÑ5OÐOÑPð
ð ×%Ñ%ð
ð 
�)˜D‘/Ñ	"ô	
ð 5ð ¨X°iÀ±oÑ-Fô ô,÷r"   rY   c                   óœ   • \ rS rSr SS\R
                  S\S\\   S\\	\      SS4
S jjr
S\4S	 jrS
\R                  SS4S jrSS jrSrg)rM   i*  NrJ   rK   r'   r/   r   c                 óä  • X l         UR                  b  UR                  R                  U l        OS U l        U R                  [        R                  [        R
                  4;   a  Ub  US   U l        OSU l        U(       a  X0l        O.[        U[        R                  5      (       a  SU l        OSU l        U R                  U l        U R                  U l        [        U=(       d    / 5      U l        g )Nr   z0.0.0.0ÚhttpsÚhttp)rK   ÚsocketÚfamilyÚaddress_familyÚAF_INETÚAF_INET6Ú	remote_ipr'   rV   r   ÚSSLIOStreamÚ_orig_remote_ipÚ_orig_protocolr5   r/   )r   rJ   rK   r'   r/   s        r   r    Ú_HTTPRequestContext.__init__+  sº   € ð Œð �=‰=Ñ$Ø"(§-¡-×"6Ñ"6ˆDÕà"&ˆDÔð ×Ñ¤F§N¡N´F·O±OÐ#DÓDØÑ#à$ Q™ZˆD�Nð 'ˆDŒNÞØ$�MÜ˜¤× 4Ñ 4×5Ñ5Ø#ˆD�Mà"ˆDŒMØ#Ÿ~™~ˆÔØ"Ÿm™mˆÔÜ"%Ð&8×&>¸BÓ"?ˆÕr"   c                 ó  • U R                   [        R                  [        R                  4;   a  U R                  $ [        U R                  [        5      (       a  [        U R                  5      $ [        U R                  5      $ r   )
rœ   rš   r�   rž   rŸ   rV   rK   r•   r   rk   r�   s    r   Ú__str__Ú_HTTPRequestContext.__str__M  sX   € Ø×Ñ¤6§>¡>´6·?±?Ð"CÓCØ—>‘>Ð!Ü˜Ÿ™¤e×,Ñ,ô ˜dŸl™lÓ+Ð+ä�t—|‘|Ó$Ð$r"   r}   c                 óØ  • UR                  SU R                  5      nS [        UR                  S5      5       5        H  nX R                  ;  d  M    O   UR                  SU5      n[
        R                  " U5      (       a  X l        UR                  SUR                  SU R                  5      5      nU(       a"  UR                  S5      S   R                  5       nUS;   a  X0l        g	g	)
z2Rewrite the ``remote_ip`` and ``protocol`` fields.zX-Forwarded-Forc              3   ó@   #   • U  H  oR                  5       v •  M     g 7fr   )Ústrip)Ú.0Úcands     r   Ú	<genexpr>Ú6_HTTPRequestContext._apply_xheaders.<locals>.<genexpr>]  s   é € ÐDÒ,C D—:‘:—<�<Ò,Cùs   ‚Ú,z	X-Real-IpzX-SchemezX-Forwarded-Protoéÿÿÿÿ)r™   r˜   N)	ÚgetrŸ   ÚreversedÚsplitr/   r   Úis_valid_ipr'   r©   )r   r}   ÚipÚproto_headers       r   Ú_apply_xheadersÚ#_HTTPRequestContext._apply_xheadersX  sÈ   € ð �[‰[Ð*¨D¯N©NÓ;ˆáD¬H°R·X±X¸c³]Ô,CÖDˆBØ×0Ñ0Õ0Ùñ Eð �[‰[˜ bÓ)ˆÜ×Ò˜r×"Ñ"ØŒNà—{‘{Ø˜Ÿ™Ð$7¸¿¹ÓGó
ˆö ð (×-Ñ-¨cÓ2°2Ñ6×<Ñ<Ó>ˆLØÐ,Ó,Ø(�Mð -r"   c                 óH   • U R                   U l        U R                  U l        g)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'   r�   s    r   Ú_unapply_xheadersÚ%_HTTPRequestContext._unapply_xheadersn  s   € ð ×-Ñ-ˆŒØ×+Ñ+ˆ�r"   )r¢   r¡   rK   rœ   r'   rŸ   r/   r   rc   )rd   re   rf   rg   r   rq   r   r   rk   r   r    r¥   r   r”   r¶   r¹   ru   r   r"   r   rM   rM   *  s€   † ð 37ñ @à×!Ñ!ð @ð ð @ð ˜3‘-ð	 @ð
 % T¨#¡YÑ/ð @ð 
õ @ðD	%˜ô 	%ð) x×';Ñ';ð )Àô )÷,,r"   rM   c                   óö   • \ rS rSrS\R
                  S\R                  SS4S jrS\\R                  \R                  4   S\R                  S\\S      4S	 jrS
\S\\S      4S jrSS jrSS jrSS jrSrg)rZ   ix  r[   rT   r   Nc                 ó   • X l         Xl        g r   ©rx   r[   )r   r[   rT   s      r   r    Ú_ProxyAdapter.__init__y  s   € ð
 'ŒØ �r"   r|   r}   c                 ó‚   • U R                   R                  R                  U5        U R                  R	                  X5      $ r   )rx   rP   r¶   r[   r�   r€   s      r   r�   Ú_ProxyAdapter.headers_received�  s1   € ð 	�‰×Ñ×/Ñ/°Ô8Ø�}‰}×-Ñ-¨jÓBÐBr"   rƒ   c                 ó8   • U R                   R                  U5      $ r   )r[   r‡   r†   s     r   r‡   Ú_ProxyAdapter.data_received‹  s   € Ø�}‰}×*Ñ*¨5Ó1Ð1r"   c                 óX   • U R                   R                  5         U R                  5         g r   )r[   rŽ   Ú_cleanupr�   s    r   rŽ   Ú_ProxyAdapter.finishŽ  s   € Ø�‰×ÑÔØ�‰�r"   c                 óX   • U R                   R                  5         U R                  5         g r   )r[   r‘   rÄ   r�   s    r   r‘   Ú!_ProxyAdapter.on_connection_close’  s   € Ø�‰×)Ñ)Ô+Ø�‰�r"   c                 óL   • U R                   R                  R                  5         g r   )rx   rP   r¹   r�   s    r   rÄ   Ú_ProxyAdapter._cleanup–  s   € Ø�‰×Ñ×1Ñ1Õ3r"   r½   rc   )rd   re   rf   rg   r   rt   rs   r    r   r   r“   r”   r   r   r�   r•   r‡   rŽ   r‘   rÄ   ru   r   r"   r   rZ   rZ   x  s¤   † ð!à×.Ñ.ð!ð ×-Ñ-ð!ð 
ô	!ðCà˜(×3Ñ3°X×5OÑ5OÐOÑPðCð ×%Ñ%ðCð 
�)˜D‘/Ñ	"ô	Cð2 5ð 2¨X°iÀ±oÑ-Fô 2ôô÷4r"   rZ   )%rh   rš   rl   Útornado.escaper   Útornado.http1connectionr   r   Útornador   r   r   Útornado.tcpserverr	   Útornado.utilr
   r_   r   r   r   r   r   r   r   r   r   ÚTYPE_CHECKINGr   rW   r   rt   rY   rr   rM   rZ   ri   ÚHTTPRequestr   r"   r   Ú<module>rÑ      sœ   ðñ 
ó Û 
å %ß TÝ Ý Ý Ý 'Ý %ã ß U× UÕ Uà	××ÝôSR�˜L¨(×*OÑ*Oô SRôl#�x×3Ñ3ô #ôLK,˜&ô K,ô\4�H×0Ñ0ô 4ðD ×(Ñ(�r"   