File: //opt/saltstack/salt/lib/python3.10/site-packages/cheroot/__pycache__/server.cpython-310.pyc
o
�N�g�* � @ s� d Z ddlmZmZmZ eZddlZddlZddl Z ddl
ZddlZddl
Z
ddlZddlZddlZddlZddlZddlZzddlmZ W n eyU ddlmZ Y nw ddlZddlmZ ddlmZ ddlmZmZm Z dd l!m"Z"m#Z# dd
l!m$Z$ ddl%m&Z& ddl'm(Z(m)Z) d
Z*e�+� dkZ, e�-dd��.d�Z/ e, o�e/ Z0 e0r�z
ddl1Z1ddl2Z2W n ey� dZ0d\Z1Z2Y nw ddl3Z3e,r�e4ed�r�e4ed�s�de_5e4ed�s�de_6e4ed�s� e$r�dnde_7dZ8dZ9dZ:dZ;d Z<d!Z=d"Z>d#Z?d$Z@d%ZAe �Bd"�Cd&eAf��ZDeE� ZFg d'�ZGe4ed(��si e_HG d)d*� d*�ZIG d+d,� d,eI�ZJG d-d.� d.�ZKG d/d0� d0�ZLG d1d2� d2�ZMG d3d4� d4�ZNG d5d6� d6�ZOG d7d8� d8�ZPG d9d:� d:�ZQd;d<d=�ZRdAd?d@�ZSdS )Bas
A high-speed, production ready, thread pooled, generic HTTP server.
For those of you wanting to understand internals of this module, here's the
basic call flow. The server's listening thread runs a very tight loop,
sticking incoming connections onto a Queue::
server = HTTPServer(...)
server.start()
-> serve()
while ready:
_connections.run()
while not stop_requested:
child = socket.accept() # blocks until a request comes in
conn = HTTPConnection(child, ...)
server.process_conn(conn) # adds conn to threadpool
Worker threads are kept in a pool and poll the Queue, popping off and then
handling each connection in turn. Each connection can consist of an arbitrary
number of requests and their responses, so we run a nested loop::
while True:
conn = server.requests.get()
conn.communicate()
-> while True:
req = HTTPRequest(...)
req.parse_request()
-> # Read the Request-Line, e.g. "GET /page HTTP/1.1"
req.rfile.readline()
read_headers(req.rfile, req.inheaders)
req.respond()
-> response = app(...)
try:
for chunk in response:
if chunk:
req.write(chunk)
finally:
if hasattr(response, "close"):
response.close()
if req.close_connection:
return
For running a server you can invoke :func:`start() <HTTPServer.start()>` (it
will run the server forever) or use invoking :func:`prepare()
<HTTPServer.prepare()>` and :func:`serve() <HTTPServer.serve()>` like this::
server = HTTPServer(...)
server.prepare()
try:
threading.Thread(target=server.serve).start()
# waiting/detecting some appropriate stop condition here
...
finally:
server.stop()
And now for a trivial doctest to exercise the test suite
>>> 'HTTPServer' in globals()
True
� )�absolute_import�division�print_functionN)� lru_cache)�queue)�urllib� )�connections�errors�__version__)�bton�ntou)�IS_PPC)�
threadpool)�MakeFile�StreamWriter)
�HTTPRequest�HTTPConnection�
HTTPServer�HeaderReader�DropUnderscoreHeaderReader�SizeCheckWrapper�KnownLengthRFile�ChunkedRFile�Gateway�get_ssl_adapter_class�WindowsZSERVER_SOFTWARE� zGoogle App Engine/F)NN�AF_INET6�IPPROTO_IPV6�) �IPV6_V6ONLY� �SO_PEERCRED� � �
s
� � � :� ;� � *� /s %2Fs (?i))s Accepts Accept-Charsets Accept-Encodings Accept-Languages
Accept-Rangess Allows
Cache-Control�
Connections Content-Encodings Content-Language� Expects If-Matchs
If-None-Matchs Pragmas Proxy-Authenticates TEs Trailer� Transfer-Encodings Upgrades Varys Vias Warnings WWW-Authenticate�
statisticsc @ s* e Zd ZdZd dd�Zdd� Zdd� ZdS )
r z`Object for reading headers from an HTTP request.
Interface and default implementation.
Nc C s� |du ri } |� � }|std��|tkr |S |�t�s!td��|d ttfv r.|�� }n!z
|�td�\}}W n tyC td��w |�� }| � |�}|}| �
|�sUq|tv rg|�|�}|rgd�
||f�}|||<