%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/web/test/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/web/test/__pycache__/test_http.cpython-312.pyc

�

Ϫ�f�f���dZddlZddlZddlZddlmZddlmZddlm	Z	m
Z
ddlmZddl
mZddl
mZmZdd	lmZmZmZdd
lmZddlZddlmZddlmZmZdd
lmZddlm Z m!Z!m"Z"ddl#m$Z$ddl%m&Z&ddl'm(Z(m)Z)ddl*m+Z+ddl,m-Z-ddl.m/Z/ddl0mZddl1m2Z2ddl3m4Z4m5Z5m6Z6ddl7m8Z8m9Z9m:Z:ddl;m<Z<m=Z=m>Z>m?Z?ddl@mAZAGd�de+e4j���ZCd�ZDGd�d e4j��ZFeDeF�ZGGd!�d"ejd�ZHGd#�d$e4j��ZIeDeI�ZJee6j��Gd%�d&eI��ZLeDeL�ZMGd'�d(eI�ZNeDeN�ZOGd)�d*e4j��ZQd+�ZRGd,�d-�ZSGd.�d/ejdeS�ZTGd0�d1eT�ZUGd2�d3eT�ZVGd4�d5eT�ZWGd6�d7ejdeS�ZXGd8�d9ejd�ZYGd:�d;ejd�ZZGd<�d=ejd�Z[Gd>�d?ejd�Z\d@�Z]GdA�dBejd�Z^GdC�dDe2�Z_GdE�dFejd�Z`GdG�dHejdeS�ZaGdI�dJejd�ZbGdK�dLejd�ZcGdM�dNe4j��ZdGdO�dPejd�ZeGdQ�dRejdeS�ZfGdS�dTejd�ZgGdU�dVejdeS�ZhdW�ZiGdX�dYejd�ZjGdZ�d[ejd�ZkGd\�d]ej��ZmGd^�d_ej��ZnGd`�daej��Zoy)bz
Test HTTP support.
�N)�BytesIO)�cycle)�Sequence�Union)�skipIf��clear_cache)�urlparse�
urlunsplit)�directlyProvides�
providedBy�provider)�verifyObject)�address)�ConnectionDone�ConnectionLost)�Clock)�EventLoggingObserver�NonStreamingProducer�StringTransport)�globalLogPublisher)�loopback)�	iterbytes�
networkString)�proxyForInterface)�Failure)�
DummyProducer)�unittest)�TestCase)�http�http_headers�iweb)�PotentialDataLoss�	_DataLoss�_IdentityTransferDecoder)�DummyChannel�bytesLinearWhitespaceComponents�sanitizedBytes�textLinearWhitespaceComponents�)�assertIsFilesystemTemporaryc��eZdZdZy)�._IDeprecatedHTTPChannelToRequestInterfaceProxyz�
    Proxy L{_IDeprecatedHTTPChannelToRequestInterface}.  Used to
    assert that the interface matches what L{HTTPChannel} expects.
    N)�__name__�
__module__�__qualname__�__doc__���</usr/lib/python3/dist-packages/twisted/web/test/test_http.pyr-r-3s��
r3r-c�<���fd�}t|t���|S)a�
    Return a callable that proxies instances of C{clsToWrap} via
        L{_IDeprecatedHTTPChannelToRequestInterface}.

    @param clsToWrap: The class whose instances will be proxied.
    @type cls: L{_IDeprecatedHTTPChannelToRequestInterface}
        implementer.

    @return: A factory that returns
        L{_IDeprecatedHTTPChannelToRequestInterface} proxies.
    @rtype: L{callable} whose interface matches C{clsToWrap}'s constructor.
    c�*���|i|��}t|�S�N)r-)�args�kwargs�instance�	clsToWraps   �r4�_makeRequestProxyz3_makeRequestProxyFactory.<locals>._makeRequestProxyLs����d�-�f�-��=�h�G�Gr3)rr
)r;r<s` r4�_makeRequestProxyFactoryr=>s!���H�
�&�
�9�(=�>��r3c��eZdZdZd�Zy)�DummyPullProducerHandlerz�
    An HTTP request handler that registers a dummy pull producer to serve the
    body.

    The owner must call C{finish} to complete the response.
    c�~�t|�|_|jd�|j|jd�y)N��F)r�_actualProducer�setResponseCode�registerProducer��selfs r4�processz DummyPullProducerHandler.process]s3��3�D�9������S�!����d�2�2�E�:r3N�r.r/r0r1rGr2r3r4r?r?Us���;r3r?c��eZdZdZd�Zd�Zy)�
DateTimeTestszTest date parsing functions.c���td�D]T}tjdd�}tj|�}tj
|�}|j
||��Vy)Ni'ri�5w)�range�random�randintr �datetimeToString�stringToDatetime�assertEqual)rF�i�time�timestr�time2s     r4�
testRoundtripzDateTimeTests.testRoundtripisU���u��	*�A��>�>�!�Z�0�D��+�+�D�1�G��)�)�'�2�E����T�5�)�		*r3c��gd�}tjd�}|D]'}|jtj|�|��)|jtjd�tjd��y)N)sSun, 06 Nov 1994 08:49:37 GMTs06 Nov 1994 08:49:37 GMTsSunday, 06-Nov-94 08:49:37 GMTs06-Nov-94 08:49:37 GMTs Sunday, 06-Nov-1994 08:49:37 GMTs06-Nov-1994 08:49:37 GMTsSun Nov  6 08:49:37 1994sNov  6 08:49:37 1994)	i�����1�%rYrYrs Thursday, 29-Sep-16 17:15:29 GMT)	i��	���r^�ir)�calendar�timegmrQr rP)rF�dateStrings�dateInt�
dateStrings    r4�testStringToDatetimez"DateTimeTests.testStringToDatetimepsp��	
���/�/�"C�D��%�	I�J����T�2�2�:�>��H�	I�����!�!�"E�F��O�O�@�A�	
r3N)r.r/r0r1rVrgr2r3r4rJrJfs��&�*�
r3rJc��eZdZd�Zy)�DummyHTTPHandlerc�.�|jjdd�|jj�}|jd�}|�t	|�j�}d|zdz|zdz}|j
d�|jd|j�|jd|j�|jd|j�|jd	d
t|�fz�|j|�|j�y)Nr�content-lengths'''
�
rAsRequestsCommandsVersion�Content-Lengths%d)�content�seek�read�	getHeader�str�encoderC�	setHeader�uri�method�clientproto�len�write�finish)rF�data�length�requests    r4rGzDummyHTTPHandler.process�s��������!�Q���|�|� � �"����� 1�2���>���[�'�'�)�F��V�#�e�+�d�2�X�=�����S�!����z�4�8�8�,����z�4�;�;�/����z�4�#3�#3�4����(�%�3�w�<�/�*A�B��
�
�7�����
r3N�r.r/r0rGr2r3r4riri�s��
r3ric��eZdZdZd�Zy)�DummyNewHTTPHandlerz�
    This is exactly like the DummyHTTPHandler but it takes only one argument
    in its constructor, with no default arguments. This exists to test an
    alternative code path in L{HTTPChannel}.
    c�0�tj||�yr7)ri�__init__)rF�channels  r4r�zDummyNewHTTPHandler.__init__�s���!�!�$��0r3N)r.r/r0r1r�r2r3r4r�r��s���1r3r�c��eZdZdZd�Zd�Zy)�DelayedHTTPHandlerzD
    Like L{DummyHTTPHandler}, but doesn't respond immediately.
    c��yr7r2rEs r4rGzDelayedHTTPHandler.process�s��r3c�.�tj|�yr7)rirGrEs r4�delayedProcessz!DelayedHTTPHandler.delayedProcess�s��� � ��&r3N)r.r/r0r1rGr�r2r3r4r�r��s���
�'r3r�c��eZdZd�Zy)�LoopbackHTTPClientc��|jdd�|jdd�|j�|jj	d�y)N�GET�/foo/barrm�
�
0123456789)�sendCommand�
sendHeader�
endHeaders�	transportryrEs r4�connectionMadez!LoopbackHTTPClient.connectionMade�s=�������-����)�2�.����������]�+r3N)r.r/r0r�r2r3r4r�r��s��,r3r�c�<�|j|j_|S)a�
    Parametrizes the L{TimeoutMixin} so that it works with whatever reactor is
    being used by the test.

    @param protocol: A L{_GenericHTTPChannel} or something implementing a
        similar interface.
    @type protocol: L{_GenericHTTPChannel}

    @param reactor: An L{IReactorTime} implementation.
    @type reactor: L{IReactorTime}

    @return: The C{channel}, with its C{callLater} method patched.
    )�	callLater�_channel)�protocol�reactors  r4�parametrizeTimeoutMixinr��s��$#*�"3�"3�H�����Or3c��eZdZdZd�Zy)�ResponseTestMixinz�
    A mixin that provides a simple means of comparing an actual response string
    to an expected response string by performing the minimal parsing.
    c�n�|D]�}|dd|d}}|d}|dd}|jdd�\}}|j�}|jd�}	|j||	�|jt	|�t	|��|dt|�}
|t|�d}|j|
|���y)a(
        Assert that the C{responses} matches the C{expected} responses.

        @type responses: C{bytes}
        @param responses: The bytes sent in response to one or more requests.

        @type expected: C{list} of C{tuple} of C{bytes}
        @param expected: The expected values for the responses.  Each tuple
            element of the list represents one response.  Each byte string
            element of the tuple is a full header line without delimiter, except
            for the last element which gives the full response body.
        N���rr*�

)�split�
splitlines�poprQ�setrx)rF�	responses�expected�response�expectedHeaders�expectedContent�expectedStatus�headers�rest�statusrns           r4�assertResponseEqualsz&ResponseTestMixin.assertResponseEquals�s���!�	7�H�/7���}�h�r�l�_�O�,�Q�/�N�-�a�b�1�O�%�O�O�K��;�M�G�T��(�(�*�G��[�[��^�F����^�V�4����S��\�3��+?�@��1�S��1�2�G��S��1�3�4�I����W�o�6�	7r3N)r.r/r0r1r�r2r3r4r�r��s���
7r3r�c�n�eZdZUdZdgZeeeeefed<d�Z	d�Z
d�Zd�Zd�Z
d	�Zd
�Zd�Zd�Zy
)�HTTP1_0Testss7GET / HTTP/1.0

GET / HTTP/1.1
Accept: text/html

)�HTTP/1.0 200 OK�
Request: /�Command: GET�Version: HTTP/1.0�Content-Length: 13�
'''
None
'''
�expected_responsec�Z�t�}tj�}t|_|j|�t
|j�D]}|j|��|jtd��|j�}|j||j�y)zZ
        Send requests over a channel and check responses match what is expected.
        zall oneN�rr �HTTPChannel�DummyHTTPHandlerProxy�requestFactory�makeConnectionr�requests�dataReceived�connectionLost�IOError�valuer�r��rF�b�a�byter�s     r4�test_bufferzHTTP1_0Tests.test_buffers���
��������0���	������d�m�m�,�	!�D�
�N�N�4� �	!�	�����+�,����	���!�!�%��)?�)?�@r3c��t�}t�}tj�}d|_|j
|_|j
|�|jd�|jd�|j|j�|jd�|jd�|j|j�|jd�|jt|j�d�y)zq
        L{HTTPChannel} resets its timeout whenever data from a request body is
        delivered to it.
        �d�&POST / HTTP/1.0
Content-Length: 2

�c�xr*N)rrr r��timeOutr�r�r��advance�assertFalse�
disconnectingrQrxr�)rF�clockr�r�s    r4�test_requestBodyTimeoutz$HTTP1_0Tests.test_requestBodyTimeouts���
���#�%�	��#�#�%�����"�_�_������	�*����M�N�
�
�
�b������0�0�1����d�#�
�
�
�b������0�0�1����d�#�����X�.�.�/��3r3c��t�}t�}tj�}|j	d�}t||�}|j
|�|jd�|jd�|j|j�|jd�|j|j�y)zA
        L{HTTPChannel}'s default timeout is 60 seconds.
        Nr��;r*)rrr �HTTPFactory�
buildProtocolr�r�r�r�r�r��
assertTrue�rFr�r��factoryr�s     r4�test_requestBodyDefaultTimeoutz+HTTP1_0Tests.test_requestBodyDefaultTimeout/s������#�%�	��"�"�$���(�(��.��*�8�U�;�����	�*����M�N�
�
�
�b������0�0�1�
�
�
�a�����	�/�/�0r3c���tj|t�}t�}t	�}tj�}|jd�}t||�}|j|�|jd�|j|j�|j|j�|jd�|j|j�|j|j�|j!dt#|��|d}|j%d|d�|jd�|j|j�|j|j�|jd�|j|j�|j|j�|j!d	t#|��|d}|j!d
|d�y)�}
        If a timed out transport doesn't close after 15 seconds, the
        L{HTTPChannel} will forcibly close it.
        Nr��<r*rzTiming out client: {peer}�
log_format��z"Forcibly timing out client: {peer})r�createWithCleanuprrrr r�r�r�r�r�r�r��disconnectedr�r��assertEqualsrx�assertIn)rF�logObserverr�r�r�r��events       r4�test_transportForciblyClosedz)HTTP1_0Tests.test_transportForciblyClosed?s���
+�<�<�T�CU�V�����#�%�	��"�"�$���(�(��.��*�8�U�;�����	�*����M�N�����0�0�1�����/�/�0�	�
�
�b�����	�/�/�0�����/�/�0����!�S��-�.��A����
�
�1�5��3F�G�	�
�
�b�����	�/�/�0�����/�/�0�
�
�
�a�����	�/�/�0����	�.�.�/����!�S��-�.��A������>��l�@S�Tr3c��t�}t�}tj�}|j	d�}t||�}|j
|�|jd�|j|j�|j|j�|jd�|j|j�|j|j�|jd�|jd�|jd�|j|j�|j|j�y)z�
        If a timed out transport ends up calling C{connectionLost}, it prevents
        the force-closure of the transport.
        Nr�r�r�r*)rrr r�r�r�r�r�r�r�r�r�r�r�r�s     r4�+test_transportNotAbortedAfterConnectionLostz8HTTP1_0Tests.test_transportNotAbortedAfterConnectionLostbs��
���#�%�	��"�"�$���(�(��.��*�8�U�;�����	�*����M�N�����0�0�1�����/�/�0�	�
�
�b�����	�/�/�0�����/�/�0�	�
�
�b������%�	�
�
�a�����	�/�/�0�����/�/�0r3c�|�t�}t�}tj�}|j	d�}d|j
_t||�}|j|�|jd�|j|j�|j|j�|jd�|j|j�|j|j�|jd�|j|j�|j|j�y)zh
        If the L{HTTPChannel} has its c{abortTimeout} set to L{None}, it never
        aborts.
        Nr�r�l)rrr r�r�r��abortTimeoutr�r�r�r�r�r�r�r�r�s     r4�,test_transportNotAbortedWithZeroAbortTimeoutz9HTTP1_0Tests.test_transportNotAbortedWithZeroAbortTimeouts���
���#�%�	��"�"�$���(�(��.��)-����&�*�8�U�;�����	�*����M�N�����0�0�1�����/�/�0�	�
�
�b�����	�/�/�0�����/�/�0�	�
�
�e�����	�/�/�0�����/�/�0r3c��t�}t�}tj�}|j	d�}t||�}|j
|�|jd�|j|j�|j|j�|jd�|jd�|j|j�|j|j�|jt�y)r�Nr�r�r`)rrr r�r�r�r�r�r�r�r�r�r�r�rr�s     r4�"test_connectionLostAfterForceClosez/HTTP1_0Tests.test_connectionLostAfterForceClose�s���
���#�%�	��"�"�$���(�(��.��*�8�U�;�����	�*����M�N�����0�0�1�����/�/�0�	�
�
�b��
�
�
�b�����	�/�/�0����	�.�.�/�
	����/r3c�Z�t�}tj�}t|_|j|�t
|j�D]}|j|��|jtd��|j�}|j||j�y)zf
        Test that a L{http.Request} subclass with no queued kwarg works as
        expected.
        �all doneNr�r�s     r4�test_noPipeliningApiz!HTTP1_0Tests.test_noPipeliningApi�s���

��������0���	������d�m�m�,�	!�D�
�N�N�4� �	!�	�����,�-����	���!�!�%��)?�)?�@r3c��t�}tj�}t|_|j|�t
|j�D]}|j|��|j�}|j|d�|jdt|j��|jr[|jdt|j��|jdj}|j�|jr�[|j�}|j||j�y)zW
        Test that pipelined requests get buffered, not processed in parallel.
        r3r*rN)rr r��DelayedHTTPHandlerProxyr�r�rr�r�r�rQrx�originalr�r�r�)rFr�r�r�r�r}s      r4�test_noPipeliningzHTTP1_0Tests.test_noPipelining�s���
��������2���	������d�m�m�,�	!�D�
�N�N�4� �	!����	��	
�����$�����C��
�
�O�,��j�j����Q��A�J�J��0��j�j��m�,�,�G��"�"�$��j�j�
���	���!�!�%��)?�)?�@r3N)r.r/r0r�r�rr�bytes�__annotations__r�r�r�r�r�r�r�r�r�r2r3r4r�r��sf��	�
�	
�	B��u�X�h�u�o�6��=�>�	�
A�4�(1� !U�F1�:1�40�4A� Ar3r�c��eZdZdZgd�Zy)�HTTP1_1Testss�GET / HTTP/1.1
Accept: text/html

POST / HTTP/1.1
Content-Length: 10

0123456789POST / HTTP/1.1
Content-Length: 10

0123456789HEAD / HTTP/1.1

))�HTTP/1.1 200 OKr�r��Version: HTTP/1.1r�r��r�r��
Command: POSTr�sContent-Length: 21�'''
10
0123456789'''
r�)r�r�s
Command: HEADr�r�r3N�r.r/r0r�r�r2r3r4r�r��s��
	�
�!�r3r�c��eZdZdZdgZy)�HTTP1_1_close_Tests�JGET / HTTP/1.1
Accept: text/html
Connection: close

GET / HTTP/1.0

)r�sConnection: closer�r�r�r�r�Nr�r2r3r4rrs��	�
�	
�
�r3rc� �eZdZdZdZd�Zd�Zy)�HTTP0_9TestssGET /
�HTTP/1.1 400 Bad Request

c�(�|j||�yr7)rQ)rFr��expectedResponses   r4r�z!HTTP0_9Tests.assertResponseEquals-s������#3�4r3c�,�tjd��)NzHTTP/0.9 not supported)r�SkipTestrEs r4r�zHTTP0_9Tests.test_noPipelining0s����� 8�9�9r3N)r.r/r0r�r�r�r�r2r3r4rr(s���H�;��5�:r3rc�@�eZdZdZdZddgZd�Zd�Zd�Zd�Z	d	�Z
d
�Zy)�PipeliningBodyTestszl
    Pipelined requests get buffered and executed in the order received,
    not processed in parallel.
    stPOST / HTTP/1.1
Content-Length: 10

0123456789POST / HTTP/1.1
Transfer-Encoding: chunked

a
0123456789
0

r�)r�r�r�r�sContent-Length: 23s'''
None
0123456789'''
c�z�t�}tj�}t|_|j|�t
|j�D]}|j|��|j|j�d�|jdt|j��|jr[|jdt|j��|jdj}|j�|jr�[|j|j�|j�y)z�
        Imitate a slow connection that delivers one byte at a time.
        The request handler (L{DelayedHTTPHandler}) is puppeted to
        step through the handling of each request.
        r3r*rN)rr r�r�r�r�rr�r�rQr�rxr�r�r��expectedResponses)rFr�r�r�r}s     r4�test_stepwiseTinyTubez)PipeliningBodyTests.test_stepwiseTinyTube\s���
��������2���	������d�m�m�,�	!�D�
�N�N�4� �	!�	
�������C�(�����C��
�
�O�,��j�j����Q��A�J�J��0��j�j��m�,�,�G��"�"�$��j�j�
	
�!�!�!�'�'�)�T�-C�-C�Dr3c�Z�t�}tj�}t|_|j|�|j
|j�|j|j�d�|jdt|j��|jr[|jdt|j��|jdj}|j�|jr�[|j|j�|j�y)z�
        Imitate a fast connection where several pipelined
        requests arrive in a single read. The request handler
        (L{DelayedHTTPHandler}) is puppeted to step through the
        handling of each request.
        r3r*rN)rr r�r�r�r�r�r�rQr�rxr�r�r�r)rFr�r�r}s    r4�test_stepwiseDumpTruckz*PipeliningBodyTests.test_stepwiseDumpTruckvs���
��������2���	�����	���t�}�}�%�	
�������C�(�����C��
�
�O�,��j�j����Q��A�J�J��0��j�j��m�,�,�G��"�"�$��j�j�
	
�!�!�!�'�'�)�T�-C�-C�Dr3c�l�t�}tj�}t|_|j|�t
|j�D]8}|j|�|jt|j�d��:|j|j�|j�y)z�
        Imitate a slow connection that delivers one byte at a time.

        (L{DummyHTTPHandler}) immediately responds, but no more
        than one
        r*N)rr r�r�r�r�rr�r��assertLessEqualrxr�r�r)rFr�r�r�s    r4�test_immediateTinyTubez*PipeliningBodyTests.test_immediateTinyTube�s���
��������0���	������d�m�m�,�	5�D�
�N�N�4� �� � ��Q�Z�Z��!�4�	5�
	
�!�!�!�'�'�)�T�-C�-C�Dr3c��t�}tj�}t|_|j|�|j
|j�|j|j�|j�y)aR
        Imitate a fast connection where several pipelined
        requests arrive in a single read. The request handler
        (L{DummyHTTPHandler}) immediately responds.

        This doesn't check the at-most-one pending request
        invariant but exercises otherwise uncovered code paths.
        See GHSA-c8m8-j448-xjx7.
        N)rr r�r�r�r�r�r�r�r�r)rFr�r�s   r4�test_immediateDumpTruckz+PipeliningBodyTests.test_immediateDumpTruck�s^��
��������0���	�����	
���t�}�}�%��!�!�!�'�'�)�T�-C�-C�Dr3c�X�t�}tj�}t|_|j|�|jt|j�zdz}|j|j|z�|j|j�|j|z�y)a�
        Imitate a fast connection where a so many pipelined
        requests arrive in a single read that backpressure is indicated.
        The request handler (L{DummyHTTPHandler}) immediately responds.

        This doesn't check the at-most-one pending request
        invariant but exercises otherwise uncovered code paths.
        See GHSA-c8m8-j448-xjx7.

        @see: L{http.HTTPChannel._optimisticEagerReadSize}
        r�N)
rr r�r�r�r��_optimisticEagerReadSizerxr�r�r�r�r)rFr�r��overLimitCounts    r4�test_immediateABiggerTruckz.PipeliningBodyTests.test_immediateABiggerTruck�s���
��������0���	������3�3�s�4�=�=�7I�I�B�N��	���t�}�}�~�5�6��!�!�!�'�'�)�T�-C�-C�n�-T�Ur3c	��t�}tj�}t|_|j|�|jt|j�z}td|dz�D]U}|j|j�|j|jddj|j|����W|j|j�|j|jd�y)z�
        When pipelined requests are received, we will optimistically continue
        receiving data up to a specified limit, then pause the transport.

        @see: L{http.HTTPChannel._optimisticEagerReadSize}
        r*�	producingz(state was {state!r} after {x} iterations)�state�x�pausedN)rr r�r�r�r�rrxr�rLr�rQ�
producerState�formatr�)rFr�r��
underLimitrs     r4�test_pipeliningReadLimitz,PipeliningBodyTests.test_pipeliningReadLimit�s���
��������2���	������/�/�3�t�}�}�3E�E�
��q�*�q�.�)�	�A�
�N�N�4�=�=�)��������:�A�A��/�/�Q�B��
�	�	
���t�}�}�%����!�/�/�8�4r3N)r.r/r0r1r�rr
rrrrr!r2r3r4r
r
4sF���	�
� 	
�	
���&E�4E�4E�(E�(V�,5r3r
c�D�eZdZdZGd�dej
�ZdZd�Zy)�
ShutdownTestszM
    Tests that connections can be shut down by L{http.Request} objects.
    c��eZdZdZd�Zy)�!ShutdownTests.ShutdownHTTPHandlerzL
        A HTTP handler that just immediately calls loseConnection.
        c�$�|j�yr7)�loseConnectionrEs r4rGz)ShutdownTests.ShutdownHTTPHandler.process�s�����!r3NrHr2r3r4�ShutdownHTTPHandlerr%�s��	�	"r3r(s1POST / HTTP/1.1
Content-Length: 10

0123456789c�F�t�}tj�}t|j�|_|j
|�|j|j�|j|j�|j�}|j|d�y)zi
        Calling L{http.Request.loseConnection} causes the transport to be
        disconnected.
        r3N)
rr r�r=r(r�r�r�r}r�r�r�rQ)rFr�r�r�s    r4�test_losingConnectionz#ShutdownTests.test_losingConnection�sz��

��������3�D�4L�4L�M���	�����	���t�|�|�$�	
������(����	�������$r3N)	r.r/r0r1r �Requestr(r}r*r2r3r4r#r#�s$���"�d�l�l�"�U�G�%r3r#c�"�eZdZdZd�Zd�Zd�Zy)�
SecurityTestsz]
    Tests that L{http.Request.isSecure} correctly takes the transport into
    account.
    c���tj�}tj�}|j	|�tj
|�}|j
|j��y)z�
        Calling L{http.Request.isSecure} when the channel is backed with a
        secure transport will return L{True}.
        N)r&�SSLr r�r�r+r��isSecure�rFr�r��reqs    r4�
test_isSecurezSecurityTests.test_isSecuresM��

����������	������l�l�1�o���������'r3c���tj�}tj�}|j	|�tj
|�}|j
|j��y)z�
        Calling L{http.Request.isSecure} when the channel is not backed with a
        secure transport will return L{False}.
        N)r&�TCPr r�r�r+r�r0r1s    r4�test_notSecurezSecurityTests.test_notSecuresO��

����������	������l�l�1�o���������(r3c�V�tj�}tj�}|j	|�tj
|�}|jj|�|jd�|j�|j|j��y)zt
        After a request is finished, calling L{http.Request.isSecure} will
        always return L{False}.
        rAN)r&r/r r�r�r+r��appendrCrzr�r0r1s    r4�test_notSecureAfterFinishz'SecurityTests.test_notSecureAfterFinish%sx��

����������	������l�l�1�o��	�
�
���#�����C� ��
�
���������(r3N)r.r/r0r1r3r6r9r2r3r4r-r-	s���
	(�	)�
)r3r-c�@�eZdZdZdZd�Zeejd�d��Z	d�Z
d�Zd�Zeejd�d	��Z
eejd
�d��Zd�Zd
�Zd�Zeejd�d��Zeejd�d��Zy)�GenericHTTPChannelTestsz�
    Tests for L{http._genericHTTPChannelProtocol}, a L{HTTPChannel}-alike which
    can handle different HTTP protocol channels.
    rc��tjd�}t|_|j	|�t|j�D]}|j|��|jtd��|jS)z{
        Run a request using the specific instance of a transport. Returns the
        negotiated protocol string.
        r3r�)r �"_genericHTTPChannelProtocolFactoryr�r�r�rr�r�r�r��_negotiatedProtocol)rF�tr�r�s    r4�'_negotiatedProtocolForTransportInstancez?GenericHTTPChannelTests._negotiatedProtocolForTransportInstanceDsm��

�3�3�C�8��0���	������d�m�m�,�	!�D�
�N�N�4� �	!�	�����,�-��$�$�$r3zHTTP/2 support not presentc��t�}tjd�}t|_d|_|j|_t�}d|_|j|�tj|j�tjtjdtjd����|j�d}|j!d�|j#|j$d�|j'|j(�tj|j�tjtjdtjd����y)zg
        When the transport is switched to H2, the HTTPChannel timeouts are
        cancelled.
        r3r��h2�	cancelledFrN)rr r=r�r�r�r�r�negotiatedProtocolr��hamcrest�assert_that�getDelayedCalls�contains�has_property�equal_tor�rQr>r�rC)rFr�r�r��
h11Timeouts     r4�test_h2CancelsH11Timeoutz0GenericHTTPChannelTests.test_h2CancelsH11TimeoutRs2������3�3�C�8��0�����	��o�o������$���	�����
	����!�!�#�����%�%���%�%�e�,��
�	
��*�*�,�Q�/�
�	
���s������.�.��6�	
���
�,�,�-�����!�!�#�����%�%���%�%�e�,��
�	
r3c�^�t�}|j|�}|j|d�y)z�
        If the transport has no support for protocol negotiation (no
        negotiatedProtocol attribute), HTTP/1.1 is assumed.
        �http/1.1N)rr@rQ�rFr�rDs   r4�test_protocolUnspecifiedz0GenericHTTPChannelTests.test_protocolUnspecified�s.��

���!�I�I�!�L�����+�[�9r3c�l�t�}d|_|j|�}|j|d�y)z�
        If the transport has no support for protocol negotiation (returns None
        for negotiatedProtocol), HTTP/1.1 is assumed.
        NrN�rrDr@rQrOs   r4�test_protocolNonez)GenericHTTPChannelTests.test_protocolNone�s6��

���#���!�I�I�!�L�����+�[�9r3c�l�t�}d|_|j|�}|j|d�y)zi
        If the transport reports that HTTP/1.1 is negotiated, that's what's
        negotiated.
        rNNrRrOs   r4�test_http11z#GenericHTTPChannelTests.test_http11�s6��

���*���!�I�I�!�L�����+�[�9r3c�l�t�}d|_|j|�}|j|d�y)z}
        If the transport reports that HTTP/2 is negotiated and HTTP/2 is
        present, that's what's negotiated.
        rBNrRrOs   r4�test_http2_presentz*GenericHTTPChannelTests.test_http2_present�s6��
���$���!�I�I�!�L�����+�U�3r3zHTTP/2 support presentc�h�t�}d|_|jt|j|�y)z�
        If the transport reports that HTTP/2 is negotiated and HTTP/2 is not
        present, an error is encountered.
        rBN)rrD�assertRaises�
ValueErrorr@�rFr�s  r4�test_http2_absentz)GenericHTTPChannelTests.test_http2_absent�s1��
���$��������8�8�
�	
r3c�h�t�}d|_|jt|j|�y)z�
        If the transport reports that a protocol other than HTTP/1.1 or HTTP/2
        is negotiated, an error occurs.
        ssmtpN)rrDrY�AssertionErrorr@r[s  r4�test_unknownProtocolz,GenericHTTPChannelTests.test_unknownProtocol�s1��

���&��������8�8�
�	
r3c��tjd�}d|j_|j	|jd�y)zK
        The C{factory} attribute is taken from the inner channel.
        r3�FooN)r r=r�r�rQ)rFr�s  r4�test_factoryz$GenericHTTPChannelTests.test_factory�s4��
�3�3�C�8��#��
�
��������F�+r3c��t�}tj|��}|jd�}|j	|j
|j
�|j	|jj
|j
�y)z�
        If C{callLater} is patched onto the L{http._GenericHTTPChannelProtocol}
        then we need to propagate it through to the backing channel.
        �r�N)rr r�r�rQr�r�)rFr�r�r�s    r4�*test_GenericHTTPChannelPropagatesCallLaterzBGenericHTTPChannelTests.test_GenericHTTPChannelPropagatesCallLater�se��
����"�"�5�1���(�(��.������+�+�U�_�_�=�����*�*�4�4�e�o�o�Fr3c�:�t�}tj|��}|jd�}|j	|j
|j
�|j	|jj
|j
�t�}d|_t|_
|j|�|jd�|j	|j
|j
�|j	|jj
|j
�y)z�
        If C{callLater} is patched onto the L{http._GenericHTTPChannelProtocol}
        then we need to propagate it across onto a new backing channel after
        upgrade.
        rdNrB�P)
rr r�r�rQr�r�rrDrir�r�r��rFr�r�r�r�s     r4�'test_genericHTTPChannelCallLaterUpgradez?GenericHTTPChannelTests.test_genericHTTPChannelCallLaterUpgrade�s�������"�"�5�1���(�(��.������+�+�U�_�_�=�����*�*�4�4�e�o�o�F�#�%�	�',�	�$�"2������	�*�	���d�#�����+�+�U�_�_�=�����*�*�4�4�e�o�o�Fr3c�~�t�}d|_tjd�}t|_|j
|�|j}|j|j|�|jd�|j|j|�|j|j|j�y)z�
        The L{_GenericHTTPChannelProtocol} will unregister its proxy channel
        from the transport if upgrade is negotiated.
        rBr3rgN)rrDr r=r�r�r�r��assertIs�producerr��assertIsNot)rFr��genericProtocol�originalChannels    r4�test_unregistersProducerz0GenericHTTPChannelTests.test_unregistersProducer�s���$�%�	�',�	�$��A�A�#�F��)>��&��&�&�y�1�)�2�2��	
�
�
�i�(�(�/�:�	�$�$�T�*�	
����+�+�_�=�	
�
�
�i�(�(�/�*B�*B�Cr3N)r.r/r0r1r�r@rr �
H2_ENABLEDrLrPrSrUrWr\r_rbrerirpr2r3r4r;r;5s����	�
�%������!=�>�/
�?�/
�b:�:�:������!=�>�4�?�4��D�O�O�5�6�
�7�
�
�,�
G������!=�>�G�?�G�0�����!=�>�D�?�Dr3r;c�N�eZdZddddd�ZdZdZdZdZd�Zd�Z	d	�Z
d
�Zd�Zd�Z
y
)�HTTPLoopbackTestsr�r��HTTP/1.0s21)srequestscommandsversionrkrc�Z�d|_|j|d�|j|d�y)Nr*rt�200)�	gotStatusrQ�rF�versionr��messages    r4�
_handleStatuszHTTPLoopbackTests._handleStatuss)���������+�.������(r3c�6�d|_|j|d�y)Nr*r�)�gotResponserQ)rFr{s  r4�_handleResponsez!HTTPLoopbackTests._handleResponse#s���������:�;r3c��|jdz|_|j|j|j�|�y�Nr*)�
numHeadersrQr��lower)rF�keyr�s   r4�
_handleHeaderzHTTPLoopbackTests._handleHeader's3���/�/�A�-�������-�-�c�i�i�k�:�E�Br3c�J�d|_|j|jd�y)Nr*�)�
gotEndHeadersrQr�rEs r4�_handleEndHeadersz#HTTPLoopbackTests._handleEndHeaders+s�����������!�,r3c�B�tj�}t|_t	�}|j
|_|j|_|j|_
|j|_tj||�}|j|j �|Sr7)r r�r�r�r�r~�handleResponser��handleHeaderr��handleEndHeadersr{�handleStatusr�
loopbackAsync�addCallback�_cbTestLoopback)rF�server�client�ds    r4�testLoopbackzHTTPLoopbackTests.testLoopback/s����!�!�#�� 5���#�%�� $� 4� 4���"�0�0���"&�"8�"8���"�0�0����"�"�6�6�2��	�
�
�d�*�*�+��r3c���|jr|jr|js;tdj	|j|j|jg���|`|`|`|`y)Nzdidn't get all callbacks {})rwr}r��RuntimeErrorrr�)rF�ignoreds  r4r�z!HTTPLoopbackTests._cbTestLoopback;sf�����4�#3�#3��8J�8J��-�4�4��^�^�T�%5�%5�t�7I�7I�J���
�

�����N��Or3N)r.r/r0r�r�rwr}r�r{r~r�r�r�r�r2r3r4rsrssJ����� �	�O��J��I��K��M�)�
<�C�-�
�
r3rsc��tjt�d�}|j�D]*\}}|jjt
|�|��,|S)zR
    Make a request with the given request headers for the persistence tests.
    F)r r+r&�items�requestHeaders�
setRawHeadersr)r�r}�
headerName�vs    r4�	_prequestr�HsQ���l�l�<�>�5�1�G� ����K�
�
�A����,�,�]�:�-F��J�K��Nr3c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�PersistenceTestsz0
    Tests for persistent HTTP connections.
    c�T�tj�|_t�|_yr7)r r�r�r�r}rEs r4�setUpzPersistenceTests.setUpWs���'�'�)��� �{��r3c���|jj|jd�}|j|�|j	gt|jjj���y)zl
        After being used for an I{HTTP/0.9} request, the L{HTTPChannel} is not
        persistent.
        sHTTP/0.9N�r��checkPersistencer}r�rQ�list�responseHeaders�getAllRawHeaders�rF�persists  r4�test_http09zPersistenceTests.test_http09[�T��
�,�,�/�/����k�J������!�����T�$�,�,�">�">�"O�"O�"Q�R�Sr3c���|jj|jd�}|j|�|j	gt|jjj���y)zl
        After being used for an I{HTTP/1.0} request, the L{HTTPChannel} is not
        persistent.
        rtNr�r�s  r4�test_http10zPersistenceTests.test_http10dr�r3c���|jj|jd�}|j|�|j	gt|jjj���y)zh
        After being used for an I{HTTP/1.1} request, the L{HTTPChannel} is
        persistent.
        �HTTP/1.1N)r�r�r}r�rQr�r�r�r�s  r4rUzPersistenceTests.test_http11msR��
�,�,�/�/����k�J������ �����T�$�,�,�">�">�"O�"O�"Q�R�Sr3c���tdg��}|jj|d�}|j|�|j	ddgfgt|jj���y)z�
        After being used for an I{HTTP/1.1} request with a I{Connection: Close}
        header, the L{HTTPChannel} is not persistent.
        sclose)�
connectionr�s
ConnectionN)r�r�r�r�rQr�r�r�)rFr}r�s   r4�test_http11Closez!PersistenceTests.test_http11Closevsf��
��z�2���,�,�/�/���E������!�����h�Z�
(�)���(�(�9�9�;�<�	
r3N)	r.r/r0r1r�r�r�rUr�r2r3r4r�r�Rs#���#�T�T�T�
r3r�c�L�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
y)
�IdentityTransferEncodingTestsz0
    Tests for L{_IdentityTransferDecoder}.
    c��g|_g|_d|_t|j|jj|jj�|_y)z�
        Create an L{_IdentityTransferDecoder} with callbacks hooked up so that
        calls to them can be inspected.
        r�N)r{rz�
contentLengthr%r8�decoderrEs r4r�z#IdentityTransferEncodingTests.setUp�sG��
��	�������/�����	�	� 0� 0�$�+�+�2D�2D�
��r3c���|jjd|jz�|j|jd|jzg�|j|j
dg�y)aC
        If L{_IdentityTransferDecoder.dataReceived} is called with a byte string
        with length equal to the content length passed to
        L{_IdentityTransferDecoder}'s initializer, the data callback is invoked
        with that string and the finish callback is invoked with a zero-length
        string.
        r�r3N�r�r�r�rQr{rzrEs r4�test_exactAmountReceivedz6IdentityTransferEncodingTests.test_exactAmountReceived�sY��	
���!�!�$��);�);�";�<�������T�D�,>�,>�%>�$?�@�������s�e�,r3c��|jjd�|j|jdg�|j|jg�|jjd|j
dz
z�|j|jdd|j
dz
zg�|j|jdg�y)a3
        If L{_IdentityTransferDecoder.dataReceived} is called multiple times
        with byte strings which, when concatenated, are as long as the content
        length provided, the data callback is invoked with each string and the
        finish callback is invoked only after the second call.
        r��yr*r3N)r�r�rQr{rzr�rEs r4�test_shortStringsz/IdentityTransferEncodingTests.test_shortStrings�s���	
���!�!�$�'�������T�F�+�������b�)����!�!�$�$�*<�*<�q�*@�"A�B�������T�4�4�3E�3E��3I�+J�$K�L�������s�e�,r3c���|jjd|jzdz�|j|jd|jzg�|j|j
dg�y)a3
        If L{_IdentityTransferDecoder.dataReceived} is called with a byte string
        with length greater than the provided content length, only the prefix
        of that string up to the content length is passed to the data callback
        and the remainder is passed to the finish callback.
        r�r�Nr�rEs r4�test_longStringz-IdentityTransferEncodingTests.test_longString�s^��	
���!�!�$��);�);�";�d�"B�C�������T�D�,>�,>�%>�$?�@�������t�f�-r3c�B���g���fd�}td|jj|���jd�|j	�g��jd��djt�|j	t�dj�d�y)z�
        If data is passed to L{_IdentityTransferDecoder.dataReceived} after the
        finish callback has been invoked, C{RuntimeError} is raised.
        c�z��	�jd�y#t$r�jt��YywxYw)N�foo)r��
BaseExceptionr8r)r�r��failuress ��r4rzzJIdentityTransferEncodingTests.test_rejectDataAfterFinished.<locals>.finish�s3���
+��$�$�V�,�� �
+�����	�*�
+�s��":�:�sxxxxr�rz;_IdentityTransferDecoder cannot decode data after finishingN)	r%r{r8r�rQ�trapr�rrr�)rFrzr�r�s  @@r4�test_rejectDataAfterFinishedz:IdentityTransferEncodingTests.test_rejectDataAfterFinished�s����
��	+�+�1�d�i�i�.>�.>��G�����X�&�����2�&����T�"�������&��������!�!�"�I�	
r3c��g}g}td|j|j�}|jd�|j|dg�|jd�|j|ddg�|j|g�y)z�
        If L{_IdentityTransferDecoder} is constructed with L{None} for the
        content length, it passes all data delivered to it through to the data
        callback.
        Nr�r�)r%r8r�rQ)rFr{rzr�s    r4�test_unknownContentLengthz7IdentityTransferEncodingTests.test_unknownContentLength�sv������*�4����f�m�m�L�����T�"������v�&����T�"������d�|�,������$r3c�t�|j|jd�|j|jd�y)z�
        Check the decoder's data and finish callbacks and make sure they are
        None in order to help avoid references cycles.
        N)�assertIdentical�dataCallback�finishCallback)rFr�s  r4�_verifyCallbacksUnreferencedz:IdentityTransferEncodingTests._verifyCallbacksUnreferenced�s0��
	
���W�1�1�4�8����W�3�3�T�:r3c���|jjd|jdz
z�|jt|jj
�|j
|j�y)z�
        L{_IdentityTransferDecoder.noMoreData} raises L{_DataLoss} if it is
        called and the content length is known but not enough bytes have been
        delivered.
        r�r*N)r�r�r�rYr$�
noMoreDatar�rEs r4�test_earlyConnectionLosez6IdentityTransferEncodingTests.test_earlyConnectionLose�sR��	
���!�!�$�$�*<�*<�q�*@�"A�B����)�T�\�\�%<�%<�=��)�)�$�,�,�7r3c��g}g}td|j|j�}|jt|j�|j|g�|j|dg�|j
|�y)z�
        L{_IdentityTransferDecoder.noMoreData} calls the finish callback and
        raises L{PotentialDataLoss} if it is called and the content length is
        unknown.
        Nr3)r%r8rYr#r�rQr�)rF�body�finishedr�s    r4�'test_unknownContentLengthConnectionLosezEIdentityTransferEncodingTests.test_unknownContentLengthConnectionLose�sk������*�4����h�o�o�N�����+�W�-?�-?�@�����r�"�����C�5�)��)�)�'�2r3c��|jjd|jz�|jj�|j	|j�y)z�
        L{_IdentityTransferDecoder.noMoreData} does not raise any exception if
        it is called when the content length is known and that many bytes have
        been delivered.
        r�N)r�r�r�r�r�rEs r4�test_finishedConnectionLosez9IdentityTransferEncodingTests.test_finishedConnectionLosesC��	
���!�!�$��);�);�";�<������!��)�)�$�,�,�7r3N)r.r/r0r1r�r�r�r�r�r�r�r�r�r�r2r3r4r�r��s9���

�
-�-�	.�
�.
%�;�8�3�8r3r�c��eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�ChunkedTransferEncodingTestsz�
    Tests for L{_ChunkedTransferDecoder}, which turns a byte stream encoded
    using HTTP I{chunked} C{Transfer-Encoding} back into the original byte
    stream.
    c��g}tj|jd�}|jd�|jd�|j	|gd��y)z�
        L{_ChunkedTransferDecoder.dataReceived} decodes chunked-encoded data
        and passes the result to the specified callback.
        N�3
abc
5
12345
sa
0123456789
��abc�12345r��r �_ChunkedTransferDecoderr8r�rQ�rF�L�ps   r4�
test_decodingz*ChunkedTransferEncodingTests.test_decodingsJ��

���(�(����4�8��	���4�5�	���-�.�����=�>r3c�(�g}g}tj|j|j�}td�D]}|j	|��|j|gd��|j|dg�|j|jg�y)z{
        L{_ChunkedTransferDecoder.dataReceived} decodes chunks broken up and
        delivered in multiple calls.
        �3
abc
5
12345
0

��a�b�c�1�2�3�4�5r3N�r r�r8rr�rQ�_trailerHeaders�rFr�r�r��ss     r4�
test_shortz'ChunkedTransferEncodingTests.test_shorts���

�����(�(����8�?�?�C���A�B�	�A�
�N�N�1��	�����L�M�����C�5�)�����*�*�B�/r3c��g}g}tj|j|j�}|jd�|jd�|jd�|j	|ddg�|j	|dg�y)zx
        L{_ChunkedTransferDecoder.dataReceived} delivers partial chunk data as
        soon as it is received.
        s	a;
12345s67890s
0;

...r�s...Nr�)rFr{r�r�s    r4�	test_longz&ChunkedTransferEncodingTests.test_long+st��
�����(�(����h�o�o�F��	���~�&�	���x� �	���+�,������(�3�4�����F�8�,r3c�4�g}g}tj|j|j�}|jd�t	d�D]$}|j|�|jd��&|j|gd��|j|dg�y)zr
        L{_ChunkedTransferDecoder.dataReceived} is robust against receiving
        a zero-length input.
        r3r�r�N)r r�r8r�rrQ)rF�chunksr�r�r�s     r4�
test_emptyz'ChunkedTransferEncodingTests.test_empty9s���
�����(�(�������H��	���s���A�B�	 �A�
�N�N�1��
�N�N�3��	 �	
����!Q�R�����C�5�)r3c��g}tj|jd�}|jd�|j	|dg�y)z
        L{_ChunkedTransferDecoder.dataReceived} doesn't treat CR LF pairs
        embedded in chunk bodies specially.
        Ns2


�
r�r�s   r4�
test_newlinesz*ChunkedTransferEncodingTests.test_newlinesHs>��

���(�(����4�8��	���'�(�����W�I�&r3c��g}tj|jd�}|jd�|j	|dg�y)zd
        L{_ChunkedTransferDecoder.dataReceived} disregards chunk-extension
        fields.
        Ns3; x-foo=bar
abc
r�r�r�s   r4�test_extensionsz,ChunkedTransferEncodingTests.test_extensionsRs>��

���(�(����4�8��	���1�2�����V�H�%r3c���d}d}d}||z|zD]W}dt|f�zdz}tjd�d��}|jtj|j
|��Yy)	z�
        L{_ChunkedTransferDecoder.dataReceived} raises
        L{_MalformedChunkedDataError} when the chunk extension fields contain
        invalid characters.

        This is a potential request smuggling vector: see GHSA-c2jg-hw38-jrqq.
        s

�\�s3; �
abc
c��yr7r2�r�s r4�<lambda>zGChunkedTransferEncodingTests.test_extensionsMalformed.<locals>.<lambda>m��r3c��yr7r2rs r4rzGChunkedTransferEncodingTests.test_extensionsMalformed.<locals>.<lambda>nrr3N)r�r r�rY�_MalformedChunkedDataErrorr�)rF�invalidControl�invalidDelimiter�
invalidDelr�r{r�s       r4�test_extensionsMalformedz5ChunkedTransferEncodingTests.test_extensionsMalformed\s��
P�	�!���
��"2�2�Z�?�	U�A��E�1�$�K�'�.�8�D��,�,����A�
���d�=�=�q�~�~�t�T�
	Ur3c��tjdd�}|jtj|jddtj
zzdz�y)a(
        L{_ChunkedTransferDecoder.dataReceived} raises
        L{_MalformedChunkedDataError} when the chunk size line exceeds 4 KiB.
        This applies even when the data has already been received and buffered
        so that behavior is consistent regardless of how bytes are framed.
        Ns3;�.r�r r�rYr	r��maxChunkSizeLineLength�rFr�s  r4�test_oversizedChunkSizeLinez8ChunkedTransferEncodingTests.test_oversizedChunkSizeLinersL��
�(�(��t�4������+�+�
�N�N��D�4�6�6�6�6��G�	
r3c��tjdd�}|jtj|jdtj
dzz�y)a	
        L{_ChunkedTransferDecoder.dataReceived} raises
        L{_MalformedChunkedDataError} when the amount of data buffered while
        looking for the end of the chunk size line exceeds 4 KiB so
        that buffering does not continue without bound.
        Nrr*rrs  r4�"test_oversizedChunkSizeLinePartialz?ChunkedTransferEncodingTests.test_oversizedChunkSizeLinePartial�sG��
�(�(��t�4������+�+�
�N�N��D�/�/�!�3�4�	
r3c��tjd�d��}|jtj|jd�y)z�
        L{_ChunkedTransferDecoder.dataReceived} raises
        L{_MalformedChunkedDataError} when the chunk size can't be decoded as
        a base-16 integer.
        c��yr7r2rs r4rzFChunkedTransferEncodingTests.test_malformedChunkSize.<locals>.<lambda>�rr3c��yr7r2rs r4rzFChunkedTransferEncodingTests.test_malformedChunkSize.<locals>.<lambda>�rr3sbloop
abc
N�r r�rYr	r�rs  r4�test_malformedChunkSizez4ChunkedTransferEncodingTests.test_malformedChunkSize�s<��
�(�(���
��	
����+�+�Q�^�^�=P�	
r3c��tjd�d��}|jtj|jd�y)z�
        L{_ChunkedTransferDecoder.dataReceived} raises
        L{_MalformedChunkedDataError} when the chunk size is negative.
        c��yr7r2rs r4rzNChunkedTransferEncodingTests.test_malformedChunkSizeNegative.<locals>.<lambda>�rr3c��yr7r2rs r4rzNChunkedTransferEncodingTests.test_malformedChunkSizeNegative.<locals>.<lambda>�rr3s	-3
abc
Nrrs  r4�test_malformedChunkSizeNegativez<ChunkedTransferEncodingTests.test_malformedChunkSizeNegative�s<��

�(�(���
��	
����+�+�Q�^�^�=M�	
r3c��tjd�d��}|jtj|jd�y)a
        L{_ChunkedTransferDecoder.dataReceived} raises
        L{_MalformedChunkedDataError} when the chunk size is prefixed with
        "0x", as if it were a Python integer literal.

        This is a potential request smuggling vector: see GHSA-c2jg-hw38-jrqq.
        c��yr7r2rs r4rzIChunkedTransferEncodingTests.test_malformedChunkSizeHex.<locals>.<lambda>�rr3c��yr7r2rs r4rzIChunkedTransferEncodingTests.test_malformedChunkSizeHex.<locals>.<lambda>�rr3s
0x3
abc
Nrrs  r4�test_malformedChunkSizeHexz7ChunkedTransferEncodingTests.test_malformedChunkSizeHex�s<��
�(�(���
��	
����+�+�Q�^�^�=N�	
r3c��tjd�d��}|jtj|jd�y)z�
        L{_ChunkedTransferDecoder.dataReceived} raises
        L{_MalformedChunkedDataError} when the chunk is followed by characters
        other than C{\r\n}.
        c��yr7r2rs r4rzEChunkedTransferEncodingTests.test_malformedChunkEnd.<locals>.<lambda>�rr3c��yr7r2rs r4rzEChunkedTransferEncodingTests.test_malformedChunkEnd.<locals>.<lambda>�rr3s
3
abc!!!!Nrrs  r4�test_malformedChunkEndz3ChunkedTransferEncodingTests.test_malformedChunkEnd�s;��
�(�(���
��	
����+�+�Q�^�^�_�	
r3c��g}tjd|j�}|jd�|j	|dg�y)z�
        L{_ChunkedTransferDecoder.dataReceived} interprets a zero-length
        chunk as the end of the chunked data stream and calls the completion
        callback.
        N�0

r3r��rFr�r�s   r4�test_finishz(ChunkedTransferEncodingTests.test_finish�s=�����(�(��x���?��	���|�$�����C�5�)r3c��g}tjd|j�}|jd�|j	|dg�y)z�
        L{_ChunkedTransferDecoder.dataReceived} passes any bytes which come
        after the terminating zero-length chunk to the completion callback.
        Ns
0

hello�hellor�r)s   r4�
test_extraz'ChunkedTransferEncodingTests.test_extra�s>��
���(�(��x���?��	���(�)�����H�:�.r3c��tjdd��}|jd�|jt|jd�y)z�
        L{_ChunkedTransferDecoder.dataReceived} raises C{RuntimeError} if it
        is called after it has seen the last chunk.
        Nc��yr7r2�r�s r4rzAChunkedTransferEncodingTests.test_afterFinished.<locals>.<lambda>�rr3r(r,)r r�r�rYr�rs  r4�test_afterFinishedz/ChunkedTransferEncodingTests.test_afterFinished�s9��

�(�(��/A�B��	���|�$����,�����Ar3c���tjdd��}|jd�|jt|j
�}|j
t|�d�y)z�
        L{_ChunkedTransferDecoder.noMoreData} raises L{_DataLoss} if it is
        called and the end of the last trailer has not yet been received.
        Nc��yr7r2r0s r4rzGChunkedTransferEncodingTests.test_earlyConnectionLose.<locals>.<lambda>�rr3s0

zYChunked decoder in 'TRAILER' state, still expecting more data to get to 'FINISHED' state.)r r�r�rYr$r�rQrr)rF�parser�excs   r4r�z5ChunkedTransferEncodingTests.test_earlyConnectionLose�sW��
�-�-�d�4F�G�����J�'����	�6�+<�+<�=�������H�
*�	
r3c�t�tjdd��}|jd�|j�y)z�
        L{_ChunkedTransferDecoder.noMoreData} does not raise any exception if
        it is called after the terminal zero length chunk is received.
        Nc��yr7r2r0s r4rzJChunkedTransferEncodingTests.test_finishedConnectionLose.<locals>.<lambda>�rr3r()r r�r�r�)rFr4s  r4r�z8ChunkedTransferEncodingTests.test_finishedConnectionLose�s1��
�-�-�d�4F�G�����L�)����r3c�����g�g����fd�}tjd|���jd�|j�g�|j�dg�y)z�
        L{_ChunkedTransferDecoder.noMoreData} can be called from the finished
        callback without raising an exception.
        c���	�j��jd�y#t$r�jt��YywxYw�NT)r�r8r�r)�extra�errorsr4�	successess ���r4r�zOChunkedTransferEncodingTests.test_reentrantFinishedNoMoreData.<locals>.finishedsC���
'��!�!�#�� � ��&��!�
)��
�
�g�i�(�
)�s�%�"A
�	A
Nr(T)r r�r�rQ)rFr�r<r4r=s  @@@r4� test_reentrantFinishedNoMoreDataz=ChunkedTransferEncodingTests.test_reentrantFinishedNoMoreData�sX���
���	�	'��-�-�d�H�=�����L�)������$�����T�F�+r3c�.�g}g}tj|j|j�}|jd�|jd�|j	|gd��|j	|dg�|j	|j
ddg�y)z�
        L{_ChunkedTransferDecoder.dataReceived} decodes chunked-encoded data
        and ignores trailer headers which come after the terminating zero-length
        chunk.
        r�s\a
0123456789
0
Server-Timing: total;dur=123.4
Expires: Wed, 21 Oct 2015 07:28:00 GMT

r�r3�Server-Timing: total;dur=123.4s&Expires: Wed, 21 Oct 2015 07:28:00 GMTN)r r�r8r�rQr�)rFr�r�r�s    r4�test_trailerHeadersz0ChunkedTransferEncodingTests.test_trailerHeaderss���
�����(�(����8�?�?�C��	���4�5�	���w�	
�	
����=�>�����C�5�)����
���1�9�
�	
r3c�*�g}g}tj|j|j�}td�D]}|j	|��|j|gd��|j|dg�|j|jdg�y)z�
        L{_ChunkedTransferDecoder.dataReceived} decodes chunks of input with
        tailer header broken up and delivered in multiple calls.
        s73
abc
5
12345
0
Server-Timing: total;dur=123.4

r�r3r@Nr�r�s     r4�test_shortTrailerHeaderz4ChunkedTransferEncodingTests.test_shortTrailerHeader(s���

�����(�(����8�?�?�C���T�
�	�A�
�N�N�1��	�	
����L�M�����C�5�)�����*�*�-N�,O�Pr3c��tjd�d��}d|_|jtj|j
d�y)z�
        L{_ChunkedTransferDecoder.dataReceived} raises
        L{_MalformedChunkedDataError} when the trailing headers data is too long.
        c��yr7r2rs r4rzHChunkedTransferEncodingTests.test_tooLongTrailerHeader.<locals>.<lambda>>rr3c��yr7r2rs r4rzHChunkedTransferEncodingTests.test_tooLongTrailerHeader.<locals>.<lambda>?rr3r�s43
abc
0
Total-Trailer: header;greater-then=10

N)r r��_maxTrailerHeadersSizerYr	r�rs  r4�test_tooLongTrailerHeaderz6ChunkedTransferEncodingTests.test_tooLongTrailerHeader8sE��

�(�(���
��$&�� �����+�+�
�N�N�M�	
r3c���tjd�d��}d|_|jd�|jd�|j	tj
|jd�y)z�
        L{_ChunkedTransferDecoder.dataReceived} raises
        L{_MalformedChunkedDataError} when the trailing headers data is too long
        and doesn't have final CRLF characters.
        c��yr7r2rs r4rzKChunkedTransferEncodingTests.test_unfinishedTrailerHeader.<locals>.<lambda>Orr3c��yr7r2rs r4rzKChunkedTransferEncodingTests.test_unfinishedTrailerHeader.<locals>.<lambda>Prr3r�s3
abc
0
01234567�
�AN)r r�rGr�rYr	rs  r4�test_unfinishedTrailerHeaderz9ChunkedTransferEncodingTests.test_unfinishedTrailerHeaderHs`��
�(�(���
��$&�� �	
���3�4�	���u������+�+�
�N�N��	
r3N)r.r/r0r1r�r�r�r�r�r�r
rrrrr"r&r*r-r1r�r�r>rArCrHrNr2r3r4r�r�s}���	?�0�-�
*�'�&�U�,
�
�
�
�
� 
�	*�/�B�
��,�*
�.Q� 
� 
r3r�c�4�eZdZgd�Zd�Zd�Zd�Zdd�Zd�Zy)	�
ChunkingTests)sabcvr3sfdfsd423s	Ffasfas
s523523

fsdfs4234c��|jD]M}djtj|��}|j	|dftj
|���O|j
ttj
d�|j
ttj
d�|j
ttj
d�y)Nr3s-5
malformed!
s0xa
malformed!
s0XA
malformed!
)�strings�joinr �toChunkrQ�	fromChunkrYrZ)rFr��chunkeds   r4�
testChunkszChunkingTests.testChunksbs������	@�A��h�h�t�|�|�A��/�G����a��X�t�~�~�g�'>�?�	@�	
���*�d�n�n�6M�N����*�d�n�n�6N�O����*�d�n�n�6N�Or3c
��dj|jD�cgc]&}djtj|����(c}�}g}d}t	|�D]1}||z}	tj
|�\}}|j
|��3|j||j�ycc}w#t$rY�awxYw)Nr3)	rSrRr rTrrUr8rZrQ)rFr?rV�result�buffer�cr{s       r4�testConcatenatedChunksz$ChunkingTests.testConcatenatedChunksjs����(�(�t�|�|�L�!�C�H�H�T�\�\�!�_�5�L�M�������7�#�	�A��a�Z�F�
�#�~�~�f�5���f��
�
�d�#�		�	
�������.��M���
��
�s�+B,�$)B1�1	B=�<B=c�~�t�}tj�}|j|�tj|d�}|jd�d|_|jjddg�|jd�|jd�|j|j�dg�y	)
zV
        Test that the L{HTTPChannel} correctly chunks responses when needed.
        FrAr��test�lemur�Hello�World!�r��Test: lemur�Transfer-Encoding: chunkeds5
Hello
6
World!
N)rr r�r�r+rCrwr�r�ryr�r�)rF�transr�r2s    r4�test_chunkedResponsesz#ChunkingTests.test_chunkedResponsesws��� �!���"�"�$�����u�%��l�l�7�E�*�����C� �%������)�)�'�H�:�>��	�	�(���	�	�)���!�!��K�K�M��
�
	
r3Nc��tj�}|rt|�|_|j	dd�}|jdd�\}}t
�}|j|�|j|dz�tt|�|zdz�D]Y}|jjrnA|jdjtj|||z|dz|z����[|jdjtjd���|jt!d��|S)z�
        Execute a web request based on plain text content, chunking
        the request payload.

        This is a stripped-down, chunking version of ParsingTests.runRequest.
        rlr�r�r*r3r�)r r�r=r��replacer�rr�r�rLrxr�r�rSrTr�r�)	rF�httpRequestr��	chunkSizer��headerr�r��poss	         r4�runChunkedRequestzChunkingTests.runChunkedRequest�s���"�"�$���%=�n�%M�G�"�!�)�)�%��9��"�(�(��a�8����#�%�	����y�)����V�k�1�2���T��i�/�!�3�4�	�C�� � �.�.��� � �������d�3��?�c�A�g��=R�&S�T�U�
�	�	���S�X�X�d�l�l�3�&7�8�9����w�z�2�3��r3c�:��g�G�fd�dtj�}d}|j||d��}|j|jj�d�|jt
��d�|j�djd	d
gi�y)a
        Test that chunked uploads are actually processed into args.

        This is essentially a copy of ParsingTests.test_multipartFormData,
        just with chunking put in.

        This fails as of twisted version 18.9.0 because of bug #9678.
        c���eZdZ�fd�Zy)�7ChunkingTests.test_multipartFormData.<locals>.MyRequestc�j���j|�|jd�|j�y�Nsdone�r8ryrz�rF�	processeds �r4rGz?ChunkingTests.test_multipartFormData.<locals>.MyRequest.process��&���� � ��&��
�
�7�#����
r3Nr~�rus�r4�	MyRequestrp�����
r3rxs�POST / HTTP/1.0
Content-Type: multipart/form-data; boundary=AaB03x
Transfer-Encoding: chunked

--AaB03x
Content-Type: text/plain
Content-Disposition: form-data; name="text"
Content-Transfer-Encoding: quoted-printable

abasdfg
--AaB03x--
r�)rj�HTTP/1.0 200 OK

doner*r�text�abasdfgN)r r+rmrQr�r�rxr8�rFrxr2r�rus    @r4�test_multipartFormDataz$ChunkingTests.test_multipartFormData�s�����	�	����	����(�(��i�1�(�E������*�*�0�0�2�4R�S�����Y���+�����1��*�*�W�z�l�,C�Dr3r�)	r.r/r0rRrWr\rfrmr~r2r3r4rPrP_s#��U�G�P�/�
�8�@!Er3rPc���eZdZdZd�Zd(d�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d �Z!d!�Z"d"�Z#d#�Z$d$�Z%d%�Z&d&�Z'd'�Z(y))�ParsingTestsz7
    Tests for protocol parsing in L{HTTPChannel}.
    c��d|_y)NF��
didRequestrEs r4r�zParsingTests.setUp�s	����r3Nc���|stj�}|rt|�|_|j	dd�}t�}|j
|�t|�D]+}|jjrn|j|��-|jtd��|r|j|j�|S|j|j�|S)a�
        Execute a web request based on plain text content.

        @param httpRequest: Content for the request which is processed. Each
            L{"
"} will be replaced with L{"
"}.
        @type httpRequest: C{bytes}

        @param requestFactory: 2-argument callable returning a Request.
        @type requestFactory: C{callable}

        @param success: Value to compare against I{self.didRequest}.
        @type success: C{bool}

        @param channel: Channel instance over which the request is processed.
        @type channel: L{HTTPChannel}

        @return: Returns the channel used for processing the request.
        @rtype: L{HTTPChannel}
        rlr�r�)r r�r=r�rhrr�rr�r�r�r�r�r�r�r�)rFrir��successr�r�r�s       r4�
runRequestzParsingTests.runRequest�s���(��&�&�(�G��%=�n�%M�G�"�!�)�)�%��9��#�%�	����y�)��k�*�	'�D�� � �.�.��� � ��&�	'�	���w�z�2�3���O�O�D�O�O�,���
���T�_�_�-��r3c�L��dj|�}g�G�fd�dtj�}|j||d��}|j	|j
j
�d�|j|j
j�|j	�g�y)aJ
        Execute a HTTP request and assert that it is rejected with a 400 Bad
        Response and disconnection.

        @param requestLines: Plain text lines of the request. These lines will
            be joined with newlines to form the HTTP request that is processed.
        @type requestLines: C{list} of C{bytes}
        rlc���eZdZ�fd�Zy)�5ParsingTests.assertRequestRejected.<locals>.MyRequestc�H���j|�|j�yr7�r8rzrts �r4rGz=ParsingTests.assertRequestRejected.<locals>.MyRequest.process����� � ��&����
r3Nr~rws�r4rxr�����
r3rxF�r�rN)	rSr r+r�rQr�r�r�r�)rF�requestLinesrirxr�rus     @r4�assertRequestRejectedz"ParsingTests.assertRequestRejected
s�����j�j��.���	�	����	�
�/�/�+�y�%�/�H��������#�#�%�/�	
�	
����)�)�7�7�8�����B�'r3c�,��g�G�fd�dtj�}d}|j||d�}|j|jj�d�|j
|jj�|j�g�y)z�
        When client sends invalid HTTP method containing
        non-ascii characters HTTP 400 'Bad Request' status will be returned.
        c���eZdZ�fd�Zy)�:ParsingTests.test_invalidNonAsciiMethod.<locals>.MyRequestc�H���j|�|j�yr7r�rts �r4rGzBParsingTests.test_invalidNonAsciiMethod.<locals>.MyRequest.process+r�r3Nr~rws�r4rxr�*r�r3rxsGE© / HTTP/1.1

rrN)r r+r�rQr�r�r�r�)rFrx�badRequestLiner�rus    @r4�test_invalidNonAsciiMethodz'ParsingTests.test_invalidNonAsciiMethod#s{���
�	�	����	�
:���/�/�.�)�Q�?������*�*�0�0�2�4W�X�����)�)�7�7�8�����B�'r3c�2��g�G�fd�dtj�}dD]t\}}tjdj	||f��}d|zdz}|j||d��j
�}|j||f|j��vy)	z�
        L{HTTPChannel} provides username and password information supplied in
        an I{Authorization} header to the L{Request} which makes it available
        via its C{getUser} and C{getPassword} methods.
        c���eZdZ�fd�Zy)�,ParsingTests.test_basicAuth.<locals>.Requestc�r��|j�|j�f|_�j|�yr7��getUser�getPassword�credentialsr8�rFr�s �r4rGz4ParsingTests.test_basicAuth.<locals>.Request.process>�+���$(�L�L�N�D�4D�4D�4F�#G�� �����%r3Nr~�r�s�r4r+r�=����
&r3r+))r��bar)r,sthere:z�:�$GET / HTTP/1.0
Authorization: Basic �

rN)	r r+�base64�	b64encoderSr�r�rQr�)rFr+�ur�r��fr2r�s       @r4�test_basicAuthzParsingTests.test_basicAuth5s������	&�d�l�l�	&�
?�	6�D�A�q�� � ����A�q�6�!2�3�A�8�1�<�w�F�A��O�O�A�w��*��,�,�.�C����a��V�S�_�_�5�	6r3c�F��g�G�fd�dtj�}gd�}|jdj|�|d��\}|j	|j
j
d�dg�|j	|j
j
d�d	d
g�y)zo
        Headers received by L{HTTPChannel} in a request are made available to
        the L{Request}.
        c���eZdZ�fd�Zy)�,ParsingTests.test_headers.<locals>.MyRequestc�H���j|�|j�yr7r�rts �r4rGz4ParsingTests.test_headers.<locals>.MyRequest.processQr�r3Nr~rws�r4rxr�Pr�r3rx)�GET / HTTP/1.0�Foo: bars	baz: Quuxs	baz: quuxr3r3rlrr�r�sbAzsQuux�quuxN�r r+r�rSrQr��
getRawHeaders�rFrxr�r}rus    @r4�test_headerszParsingTests.test_headersIs����
�	�	����	�

��	
����
�
�<�0�)�Q�?��	������/�/�=�=�f�E��x�P�����"�"�0�0��8�7�G�:L�	
r3c����g�G�fd�dtj�}gd�}|jdj|�|d��\}|j	|j
j
d�dg�|j	|j
j
d�dg�|j	|j
j
d	�d
g�|j	|j
j
d�dg�y
)aC
        Line folded headers are handled by L{HTTPChannel} by replacing each
        fold with a single space by the time they are made available to the
        L{Request}. Any leading whitespace in the folded lines of the header
        value is replaced with a single space, per:

            A server that receives an obs-fold in a request message ... MUST
            ... replace each received obs-fold with one or more SP octets prior
            to interpreting the field value or forwarding the message
            downstream.

        See RFC 7230 section 3.2.4.
        c���eZdZ�fd�Zy)�5ParsingTests.test_headersMultiline.<locals>.MyRequestc�H���j|�|j�yr7r�rts �r4rGz=ParsingTests.test_headersMultiline.<locals>.MyRequest.processvr�r3Nr~rws�r4rxr�ur�r3rx)
r�s	nospace: s	 nospace	sspace:spaces spacesspaces: spacess  spacess	   spacesstab: ts	as	br3r3rlrsnospacesspacesspace space�spacessspaces spaces spacesstabst a bNr�r�s    @r4�test_headersMultilinez"ParsingTests.test_headersMultilinees�����	�	����	�

�� 	
����
�
�<�0�)�Q�?��	��	
����"�"�0�0��<�
�L�	
�	
����"�"�0�0��:�
��	
�	
����"�"�0�0��;�
$�%�	
�	
����"�"�0�0��8�
�J�	
r3c�L��g�G�fd�dtj�}gd�}|jdj|�|d��\}|j	|j
j
d�dg�|j	|j
j
d�d	g�|j	|j
j
d
�dg�|j	|j
j
d�d
g�|j	|j
j
d�dg�y)z�
        Leading and trailing space and tab characters are stripped from
        headers. Other forms of whitespace are preserved.

        See RFC 7230 section 3.2.3 and 3.2.4.
        c���eZdZ�fd�Zy)�:ParsingTests.test_headerStripWhitespace.<locals>.MyRequestc�H���j|�|j�yr7r�rts �r4rGzBParsingTests.test_headerStripWhitespace.<locals>.MyRequest.process�r�r3Nr~rws�r4rxr��r�r3rx)r�s!spaces:   spaces were stripped   stabs: 		tabs were stripped		s5spaces-and-tabs: 	 	 spaces and tabs were stripped	 	s*line-tab:    vertical tab was preserved	s(form-feed:  form feed was preserved   r3r3rlrr�sspaces were strippedstabsstabs were strippedsspaces-and-tabssspaces and tabs were strippedsline-tabs vertical tab was preserveds	form-feeds form feed was preserved Nr�r�s    @r4�test_headerStripWhitespacez'ParsingTests.test_headerStripWhitespace�s����	�	����	�
	
��	
����
�
�<�0�)�Q�?��	��	
����"�"�0�0��;�
$�%�	
�	
����"�"�0�0��9�
"�#�	
�	
����"�"�0�0�1C�D�
-�.�	
�	
����"�"�0�0��=�
/�0�	
�	
����"�"�0�0��>�
-�.�	
r3c���dg}ttjjdz�D]}|j	t|�d����!|j
ddg�|j|�y)z�
        C{HTTPChannel} enforces a limit of C{HTTPChannel.maxHeaders} on the
        number of headers received per request.
        r�r�z: foor3N)rLr r��
maxHeadersr8r�extendr�)rFr�rRs   r4�test_tooManyHeadersz ParsingTests.test_tooManyHeaders�sj��
*�*���t�'�'�2�2�Q�6�7�	<�A����
���5�k� :�;�	<����S�#�J�'��"�"�<�0r3c�*�|jgd��y)z�
        If a I{Content-Length} header with a non-integer value is received,
        a 400 (Bad Request) response is sent to the client and the connection
        is closed.
        )r�sContent-Length: xr3r3N�r�rEs r4�test_invalidContentLengthHeaderz,ParsingTests.test_invalidContentLengthHeader����	
�"�"�
�	
r3c�*�|jgd��y)z�
        If a header without colon is received a 400 (Bad Request) response
        is sent to the client and the connection is closed.
        )r�sHeaderName r3r3Nr�rEs r4�test_invalidHeaderNoColonz&ParsingTests.test_invalidHeaderNoColon�s��
	
�"�"�
�	
r3c�*�|jgd��y)z�
        C{HTTPChannel} rejects a request with an empty header name (i.e.
        nothing before the colon).  It produces a 400 (Bad Request) response is
        generated and closes the connection.
        )r�s: foor3r3Nr�rEs r4�test_invalidHeaderOnlyColonz(ParsingTests.test_invalidHeaderOnlyColon�r�r3c�*�|jgd��y)z�
        C{HTTPChannel} rejects a request containing a header with whitespace
        between the header name and colon as requried by RFC 7230 section
        3.2.4. A 400 (Bad Request) response is generated and the connection
        closed.
        )r�sHeaderName : foor3r3Nr�rEs r4�'test_invalidHeaderWhitespaceBeforeColonz4ParsingTests.test_invalidHeaderWhitespaceBeforeColon	s��	
�"�"�
�	
r3c���g�G�fd�dtj�}|jtjdd�gd�}|j	dj|�|d�}�\}}|j
|jd�d	�|j
|jd	�d
�|j
|jj�d�y)
z�
        C{HTTPChannel} enforces the limit of C{HTTPChannel.maxHeaders} per
        request so that headers received in an earlier request do not count
        towards the limit when processing a later request.
        c���eZdZ�fd�Zy)�:ParsingTests.test_headerLimitPerRequest.<locals>.MyRequestc�H���j|�|j�yr7r�rts �r4rGzBParsingTests.test_headerLimitPerRequest.<locals>.MyRequest.process"r�r3Nr~rws�r4rxr�!r�r3rxr�r*)�GET / HTTP/1.1r�r3r3r�sBar: bazr3r3rlrr�r��baz�hHTTP/1.1 200 OK
Transfer-Encoding: chunked

0

HTTP/1.1 200 OK
Transfer-Encoding: chunked

0

N)
r r+�patchr�r�rSrQrqr�r�)rFrxr�r��first�secondrus      @r4�test_headerLimitPerRequestz'ParsingTests.test_headerLimitPerRequests�����	�	����	�
	
�
�
�4�#�#�\�1�5�	
���/�/�%�*�*�\�":�I�q�I��#�����������0�&�9�����)�)�&�1�6�:�������#�#�%�	
�	
r3c���g�G�fd�dtj�}tj�}d|_d}|j	|||d��}|j�g�|j|jj�d�y)	z�
        Enforces a limit of C{HTTPChannel.totalHeadersSize}
        on the size of headers received per request starting from initial
        command line.
        c���eZdZ�fd�Zy)�@ParsingTests.test_headersTooBigInitialCommand.<locals>.MyRequestc�H���j|�|j�yr7r�rts �r4rGzHParsingTests.test_headersTooBigInitialCommand.<locals>.MyRequest.processMr�r3Nr~rws�r4rxr�Lr�r3rxr�s"GET /path/longer/than/10 HTTP/1.1
F�rir�r�r�rN�r r+r��totalHeadersSizer�rQr�r��rFrxr�rirus    @r4� test_headersTooBigInitialCommandz-ParsingTests.test_headersTooBigInitialCommandDs�����	�	����	�
�"�"�$��#%�� �<���/�/�#�$���	"�
��	
����B�'�����*�*�0�0�2�4W�Xr3c���g�G�fd�dtj�}tj�}d|_d}|j	|||d��}|j�g�|j|jj�d�y)	z�
        Enforces a limit of C{HTTPChannel.totalHeadersSize}
        on the size of headers received per request counting first line
        and total headers.
        c���eZdZ�fd�Zy)�>ParsingTests.test_headersTooBigOtherHeaders.<locals>.MyRequestc�H���j|�|j�yr7r�rts �r4rGzFParsingTests.test_headersTooBigOtherHeaders.<locals>.MyRequest.processhr�r3Nr~rws�r4rxr�gr�r3rx�(s5GET /less/than/40 HTTP/1.1
Some-Header: less-than-40
Fr�rNr�r�s    @r4�test_headersTooBigOtherHeadersz+ParsingTests.test_headersTooBigOtherHeaders_s�����	�	����	�
�"�"�$��#%�� �T���/�/�#�$���	"�
��	
����B�'�����*�*�0�0�2�4W�Xr3c��Gd�dtj�}tj�}d|_||_d}|j||d��}|j
|jj�d�y)	z�
        Enforces total size of headers per individual request and counter
        is reset at the end of each request.
        c��eZdZd�Zy)�@ParsingTests.test_headersTooBigPerRequest.<locals>.SimpleRequestc�$�|j�yr7)rzrEs r4rGzHParsingTests.test_headersTooBigPerRequest.<locals>.SimpleRequest.process�s�����
r3Nr~r2r3r4�
SimpleRequestr��s��
r3r�r�sZGET / HTTP/1.1
Some-Header: total-less-than-60

GET / HTTP/1.1
Some-Header: less-than-60

F)rir�r�r�N)	r r+r�r�r�r�rQr�r�)rFr�r�ris    r4�test_headersTooBigPerRequestz)ParsingTests.test_headersTooBigPerRequestzs��	�D�L�L�	��"�"�$��#%�� �!.���
�	��/�/�#�W�e�"�
��	
������#�#�%�	
�	
r3c����d}i�|�G��fd�dtj�}|j||�|j�dddd��y)	z3
        Test cookies parsing and reading.
        sKGET / HTTP/1.0
Cookie: rabbit="eat carrot"; ninja=secret; spam="hey 1=1!"

c���eZdZ��fd�Zy)�+ParsingTests.testCookies.<locals>.MyRequestc�j��dD]}|j|��|<�d�_|j�y)N�srabbitsninjasspamT)�	getCookier�rz)rF�name�cookies�testcases  ��r4rGz3ParsingTests.testCookies.<locals>.MyRequest.process�s5���:�9�D�$(�N�N�4�$8�G�D�M�9�&*��#����
r3Nr~)r�r�s��r4rxr��s���
r3rxs"eat carrot"ssecrets
"hey 1=1!"r�N�r r+r�rQ)rFrirxr�r�s   @@r4�testCookieszParsingTests.testCookies�sQ�����
����	����	�	
����Y�/�����'�9�}�U�	
r3c������d}g�g�|�G���fd�dtj�}|j||�|j�dg�|j�dgdgddgg�y)	NsJGET /?key=value&multiple=two+words&multiple=more%20words&empty= HTTP/1.0

c���eZdZ���fd�Zy)�'ParsingTests.testGET.<locals>.MyRequestc�����j|j��j|jd|jd|jdg�d�_|j�y�NskeysemptysmultipleT)r8rvr�r8r�rz)rFr8rvr�s ���r4rGz/ParsingTests.testGET.<locals>.MyRequest.process�sW����
�
�d�k�k�*�����Y�Y�v�&��	�	�(�(;�T�Y�Y�{�=S�T��'+��#����
r3Nr~)r8rvr�s���r4rxr��s���
r3rxr��valuer3�	two words�
more wordsr�)rFrirxr8rvr�s   @@@r4�testGETzParsingTests.testGET�sr�����������	�	����	�	
����Y�/�����&��*������
�S�E�L�-�3P�Q�Rr3c������d}g�g�g�|�G����fd�dtj�}|j||�|j�dg�|j�dg�|j�dgdgg�y)	z�
        While only a single '?' is allowed in an URL, several other servers
        allow several and pass all after the first through as part of the
        query arguments.  Test that we emulate this behavior.
        s"GET /foo?bar=?&baz=quux HTTP/1.0

c���eZdZ����fd�Zy)�6ParsingTests.test_extraQuestionMark.<locals>.MyRequestc����j|j��j|j��j|jd|jdg�d�_|j
�y)Nr�r�T)r8rv�pathr�r8r�rz)rFr8rvrr�s ����r4rGz>ParsingTests.test_extraQuestionMark.<locals>.MyRequest.process�sW����
�
�d�k�k�*����D�I�I�&����T�Y�Y�v�.��	�	�&�0A�B�C�&*��#����
r3Nr~)r8rvrr�s����r4rxr�s
���
�
r3rxr�s/foo�?r�Nr�)rFrirxr8rvrr�s   @@@@r4�test_extraQuestionMarkz#ParsingTests.test_extraQuestionMark�s����>����������	�	����	�	
����Y�/�����&��*������y�)��������	�2�3r3c�B�����d}tdt|�|fz�}g�g�g�|�G����fd�dtj�}|j	||�|j�dg�|j�dgdgdd	gg�|j�t|�g�y
)a]
        The request body of a I{POST} request with a I{Content-Type} header
        of I{application/x-www-form-urlencoded} is parsed according to that
        content type and made available in the C{args} attribute of the
        request object.  The original bytes of the request may still be read
        from the C{content} attribute.
        z9key=value&multiple=two+words&multiple=more%20words&empty=zVPOST / HTTP/1.0
Content-Length: %d
Content-Type: application/x-www-form-urlencoded

%sc���eZdZ����fd�Zy)�4ParsingTests.test_formPOSTRequest.<locals>.MyRequestc�2���j|j��j|jd|jd|jdg��j|jj��d�_|j�yr�)r8rvr�r8rnrpr�rz)rFr8rnrvr�s ����r4rGz<ParsingTests.test_formPOSTRequest.<locals>.MyRequest.process	sp����
�
�d�k�k�*�����Y�Y�v�&��	�	�(�(;�T�Y�Y�{�=S�T�����t�|�|�0�0�2�3�&*��#����
r3Nr~)r8rnrvr�s����r4rxr
	s
���
�
r3rxsPOSTrr3rrN)rrxr r+r�rQ)rF�queryrirxr8rnrvr�s    @@@@r4�test_formPOSTRequestz!ParsingTests.test_formPOSTRequest�s����L��#�
��5�z�5�!�

"�
����������	�	����	�	
����Y�/�����'��+������
�S�E�L�-�3P�Q�R�	
����=��#7�"8�9r3c��d}|j|tjd��}|j|jj�d�y)zX
        When the multipart processing fails the client gets a 400 Bad Request.
        sPOST / HTTP/1.0
Content-Type: multipart/form-data; boundary=☃
Content-Length: 103

--☃
Content-Type: text/plain
Content-Length: 999999999999999999999999999999999999999999999999999999999999999
Content-Transfer-Encoding: quoted-printable

abasdfg
--☃--
Fr�rN)r�r r+rQr�r�)rFr2r�s   r4�test_multipartProcessingFailurez,ParsingTests.test_multipartProcessingFailure	sC�����/�/�#�t�|�|�U�/�C������*�*�0�0�2�4W�Xr3c���g�G�fd�dtj�}d}|j||d��}|j|jj�d�|j�dji�y)	zS
        When the multipart does not contain a header is should be skipped
        c���eZdZ�fd�Zy)�JParsingTests.test_multipartEmptyHeaderProcessingFailure.<locals>.MyRequestc�j���j|�|jd�|j�yrrrsrts �r4rGzRParsingTests.test_multipartEmptyHeaderProcessingFailure.<locals>.MyRequest.process2	rvr3Nr~rws�r4rxr1	ryr3rxsrPOST / HTTP/1.0
Content-Type: multipart/form-data; boundary=AaBb1313
Content-Length: 14

--AaBb1313

--AaBb1313--
Fr�rzrN)r r+r�rQr�r�r8r}s    @r4�*test_multipartEmptyHeaderProcessingFailurez7ParsingTests.test_multipartEmptyHeaderProcessingFailure+	sq����	�	����	����/�/�#�y�%�/�@������*�*�0�0�2�4R�S�����1��*�*�B�/r3c�:��g�G�fd�dtj�}d}|j||d��}|j|jj�d�|jt
��d�|j�djd	d
gi�y)z�
        If the request has a Content-Type of C{multipart/form-data}, and the
        form data is parseable, the form arguments will be added to the
        request's args.
        c���eZdZ�fd�Zy)�6ParsingTests.test_multipartFormData.<locals>.MyRequestc�j���j|�|jd�|j�yrrrsrts �r4rGz>ParsingTests.test_multipartFormData.<locals>.MyRequest.processO	rvr3Nr~rws�r4rxrN	ryr3rxs�POST / HTTP/1.0
Content-Type: multipart/form-data; boundary=AaB03x
Content-Length: 149

--AaB03x
Content-Type: text/plain
Content-Disposition: form-data; name="text"
Content-Transfer-Encoding: quoted-printable

abasdfg
--AaB03x--
Fr�rzr*rr{r|N)r r+r�rQr�r�rxr8r}s    @r4r~z#ParsingTests.test_multipartFormDataF	s�����	�	����	����/�/�#�y�%�/�@������*�*�0�0�2�4R�S�����Y���+�����1��*�*�W�z�l�,C�Dr3c	���g�G�fd�dtj�}d}dtt|j	dd���zdz}|j|j
d�|z|d	�
�}|j|jj�d�|jt��d�|j�d
jddgi�y)z�
        If the request has a Content-Type of C{multipart/form-data},
        and the form data is parseable and contains files, the file
        portions will be added to the request's args.
        c���eZdZ�fd�Zy)�6ParsingTests.test_multipartFileData.<locals>.MyRequestc�j���j|�|jd�|j�yrrrsrts �r4rGz>ParsingTests.test_multipartFileData.<locals>.MyRequest.processo	rvr3Nr~rws�r4rxrn	ryr3rxs�-----------------------------738837029596785559389649595
Content-Disposition: form-data; name="uploadedfile"; filename="test"
Content-Type: application/octet-stream

abasdfg
-----------------------------738837029596785559389649595--
z�POST / HTTP/1.0
Content-Type: multipart/form-data; boundary=---------------------------738837029596785559389649595
Content-Length: rlr�z


�asciiFr�rzr*rsuploadedfiler|N)r r+rrrxrhr�rsrQr�r�r8)rFrxr�r2r�rus     @r4�test_multipartFileDataz#ParsingTests.test_multipartFileDataf	s�����	�	����	���
��#�d�l�l�5�'�2�3�4�	
5�
�
�	��/�/�#�*�*�W�"5��"<�i�QV�/�W������*�*�0�0�2�4R�S�����Y���+�����1��*�*�_�z�l�,K�Lr3c�~������d}g�g�g�g�|�G�����fd�dtj�}|j||�|j�dj�t|�d�|j
�dd�|j
�dg�|j
�dg�|j
�d	g�y	)
z�
        If a request uses the I{chunked} transfer encoding, the request body is
        decoded accordingly before it is made available on the request.
        shGET / HTTP/1.0
Content-Type: text/plain
Transfer-Encoding: chunked

6
Hello,
14
 spam,eggs spam spam
0

c� ��eZdZ�����fd�Zy)�4ParsingTests.test_chunkedEncoding.<locals>.MyRequestc����j|j��j|jj��t�|_�j|j��j|j
��j|jj�d�_|j�yr:)
r8rnrprrvrr��_transferDecoderr�rz)rFrnr�rvrr�s �����r4rGz<ParsingTests.test_chunkedEncoding.<locals>.MyRequest.process�	s~������t�|�|�,����t�|�|�0�0�2�3� '�y����
�
�d�k�k�*����D�I�I�&����t�|�|�<�<�=�&*��#����
r3Nr~)rnr�rvrr�s�����r4rxr$�	s
���

�

r3rxrr*sHello, spam,eggs spam spamr��/N)r r+r��
addCleanup�closer+rQ)rFrirxrnr�rvrr�s   @@@@@r4�test_chunkedEncodingz!ParsingTests.test_chunkedEncoding�	s����
������������	�	����	�	
����Y�/�	
�����
�(�(�)�#�D�'�!�*�5�������%B�C�����&��*������v�&�����4�&�)r3c�.��d}g�G�fd�dtj�}|j||d��}|j�d�|j	|j
j
�d�|j|j
j�y)	z�
        If a request uses the I{chunked} transfer encoding, but provides an
        invalid chunk length value, the request fails with a 400 error.
        s�GET / HTTP/1.1
Content-Type: text/plain
Transfer-Encoding: chunked

MALFORMED_LINE_THIS_SHOULD_BE_'6'
Hello,
14
 spam,eggs spam spam
0

c���eZdZ�fd�Zy)�=ParsingTests.test_malformedChunkedEncoding.<locals>.MyRequestc�(���jd�yr:�r8)rFr�s �r4rGzEParsingTests.test_malformedChunkedEncoding.<locals>.MyRequest.process�	s����!�!�$�'r3Nr~r�s�r4rxr-�	s���
(r3rxFr�zRequest.process calledrN)	r r+r�r�rQr�r�r�r�)rFrirxr�r�s    @r4�test_malformedChunkedEncodingz*ParsingTests.test_malformedChunkedEncoding�	s�������
�	(����	(�
�/�/�+�y�%�/�H������%=�>�����*�*�0�0�2�4W�X�����)�)�7�7�8r3c�:�	�tj|t�}g�	G�	fd�dtj�}d}d}tjdj||f��}d|zdz}|jt
dd	��|j||d
��	j�}|jd|j�|jdt|��|d
}|d
}|j|j t"�|j%t"�y)z�
        A L{Request} that throws an exception processing basic authorization
        logs an error and uses an empty username and password.
        c���eZdZ�fd�Zy)�5ParsingTests.test_basicAuthException.<locals>.Requestc�r��|j�|j�f|_�j|�yr7r�r�s �r4rGz=ParsingTests.test_basicAuthException.<locals>.Request.process�	r�r3Nr~r�s�r4r+r3�	r�r3r+r�r�r�r�r��	b64decodec��gSr7r2)rs r4rz6ParsingTests.test_basicAuthException.<locals>.<lambda>�	s��"�r3r)r3r3r*�log_failureN)rr�rr r+r�r�rSr�r�r�rQr�r�rx�assertIsInstancer��AttributeError�flushLoggedErrors)
rFr�r+r�r�r�r�r2r�r�s
         @r4�test_basicAuthExceptionz$ParsingTests.test_basicAuthException�	s����
+�<�<�T�CU�V����	&�d�l�l�	&�

�������T�Y�Y��1�v�.�/��4�q�8�7�B���
�
�6�;��5�����7�A�&��l�l�n������S�_�_�5����!�S��-�.��A����-� �����a�g�g�~�6����~�.r3c�*�|jgd��y)z�
        A request which includes multiple C{content-length} headers
        fails with a 400 response without calling L{Request.process}.
        )�GET /a HTTP/1.1�Content-Length: 56�Content-Length: 0�Host: host.invalidr3r3Nr�rEs r4�test_duplicateContentLengthsz)ParsingTests.test_duplicateContentLengths�	s��
	
�"�"�
�		
r3c	�8�|jdddddddzg�y)z�
        A request with a non-integer C{Content-Length} header fails with a 400
        response without calling L{Request.process}.
        r=s(Content-Length: MORE THAN NINE THOUSAND!r@r3r�i)#Nr�rEs r4�test_contentLengthMalformedz(ParsingTests.test_contentLengthMalformed
s-��
	
�"�"�"�;�%����t��

�		
r3c�*�|jgd��y)z�
        A request with a C{Content-Length} header that begins with a L{+} fails
        with a 400 response without calling L{Request.process}.

        This is a potential request smuggling vector: see GHSA-c2jg-hw38-jrqq.
        )r=sContent-Length: +100r@r3r3sdxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxNr�rEs r4�test_contentLengthTooPositivez*ParsingTests.test_contentLengthTooPositive
���	
�"�"�
�		
r3c�*�|jgd��y)z�
        A request with a C{Content-Length} header that is negative fails with
        a 400 response without calling L{Request.process}.

        This is a potential request smuggling vector: see GHSA-c2jg-hw38-jrqq.
        )r=sContent-Length: -100r@r3r3s�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxNr�rEs r4�test_contentLengthNegativez'ParsingTests.test_contentLengthNegative'
rFr3c�*�|jgd��y)z�
        Two pipelined requests, the first of which includes multiple
        C{content-length} headers, trigger a 400 response without
        calling L{Request.process}.
        )
r=r>r?r@r3r3r=r@r3r3Nr�rEs r4�1test_duplicateContentLengthsWithPipelinedRequestsz>ParsingTests.test_duplicateContentLengthsWithPipelinedRequests9
���	
�"�"�
�
	
r3c�*�|jgd��y)z�
        A request that includes both C{content-length} and
        C{transfer-encoding} headers fails with a 400 response without
        calling L{Request.process}.
        )r=rdr?r@r3r3Nr�rEs r4�%test_contentLengthAndTransferEncodingz2ParsingTests.test_contentLengthAndTransferEncodingN
s��	
�"�"�
�		
r3c�*�|jgd��y)z�
        Two pipelined requests, the first of which includes both
        C{content-length} and C{transfer-encoding} headers, triggers a
        400 response without calling L{Request.process}.
        )
r=rdr?r@r3r3r=r@r3r3Nr�rEs r4�:test_contentLengthAndTransferEncodingWithPipelinedRequestszGParsingTests.test_contentLengthAndTransferEncodingWithPipelinedRequests_
rKr3c�*�|jgd��y)z�
        A request whose C{transfer-encoding} header includes a value
        other than C{chunked} or C{identity} fails with a 400 response
        without calling L{Request.process}.
        )r=sTransfer-Encoding: unknownr@r3r3Nr�rEs r4�test_unknownTransferEncodingz)ParsingTests.test_unknownTransferEncodingt
s��	
�"�"�
�	
r3c����g�G�fd�dtj�}d}|j||d�}|j�dg�|j|jj�d�y)z�
        A request with a valid C{content-length} and a
        C{transfer-encoding} whose value is C{identity} succeeds.
        c���eZdZdZ�fd�Zy)�EParsingTests.test_transferEncodingIdentity.<locals>.SuccessfulRequestFc����j|jj��|jdd�|j	�y)Nrk�0)r8rnrprtrz)rFr�s �r4rGzMParsingTests.test_transferEncodingIdentity.<locals>.SuccessfulRequest.process�
s4������D�L�L�-�-�/�0����0�$�7����
r3N)r.r/r0rurG)r�s�r4�SuccessfulRequestrT�
s
����I�
r3rWsTGET / HTTP/1.1
Host: host.invalid
Content-Length: 2
Transfer-Encoding: identity

ok
Fsoks&HTTP/1.1 200 OK
Content-Length: 0

N)r r+r�rQr�r�)rFrWr}r�r�s    @r4�test_transferEncodingIdentityz*ParsingTests.test_transferEncodingIdentity�
sk���
��	����	����/�/�'�+<�e�D�������w�'�������#�#�%�;�	
r3)NTN))r.r/r0r1r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr
rrrr~r!r*r0r;rArCrErHrJrMrOrQrXr2r3r4r�r��s���� �)�V(�2(�$6�(
�88
�t0
�d
1�

�
�

�
� )
�VY�6Y�6&
�P
�4S�,4�4':�RY�,0�6E�@$M�L.*�`9�</�6
� 
� 
�$
�$
�*
�"
�*
� 
r3r�c��eZdZd�Zd�Zy)�QueryArgumentsTestsc���d�}�fd�}t�|�D]}||d�||d��t�|�D]}||d�||d��|�D](}t�||d�t�||d��*y)z�
        For a given URL, L{http.urlparse} should behave the same as L{urlparse},
        except it should always return C{bytes}, never text.
        c3�K�dD]F}dD]?}dD]8}dD]1}|��|dztt|��z}t|||ddf����3�:�A�Hy�w)N)shttpshttps)�example.com)Nr�)r3spathr�r3)rrrr)�scheme�host�portrs    r4�urlsz/QueryArgumentsTests.test_urlparse.<locals>.urls�
s}����-�
Q��-�Q�D� +�Q��$2�Q�D�#�/�'+�d�{�]�3�t�9�5M�'M��&0�&�$��c�3�1O�&P� P�Q�Q�Q�
Q�s
�A�5Ac���|}|r|jd�}t|�}t|jt�r�|jjd�|jjd�|jjd�|jjd�|jjd�|jjd�f}nD|j|j|j|j|j|jf}tj|�\}}}}}	}
�j|||||	|
f|��j|t��j|t��j|t��j|t��j|	t��j|
t�y)z�
            Verify that C{url} is parsed into the same objects by both
            L{http.urlparse} and L{urlparse}.
            r zutf-8N)�decoder
�
isinstancer^rrrs�netlocr�paramsr�fragmentr rQr8r�)�urlrc�urlToStandardImplementation�standardResultr�r^rerrfrrgrFs           �r4�assertSameParsingz<QueryArgumentsTests.test_urlparse.<locals>.assertSameParsing�
s����
+.�'��.1�j�j��.A�+�
&�&A�B�N��.�/�/��5�#�)�)�0�0��9�"�)�)�0�0��9�"�'�'�.�.�w�7�"�)�)�0�0��9�"�(�(�/�/��8�"�+�+�2�2�7�;�
��#�)�)�"�)�)�"�'�'�"�)�)�"�(�(�"�+�+�
��=A�M�M�#�<N�9�F�F�D�&�%�����f�f�d�F�E�8�L�h�W��!�!�&�%�0��!�!�&�%�0��!�!�$��.��!�!�&�%�0��!�!�%��/��!�!�(�E�2r3TFNr)rFrarkrhs`   r4�
test_urlparsez!QueryArgumentsTests.test_urlparse�
s����	Q�)	3�X	�
��6�	*�C��c�4�(��c�5�)�	*�
	�
��6�	)�C��c�5�)��c�4�(�	)�
�6�	*�C��M��c�4�(��M��c�5�)�		*r3c�N�|jttjd�y)zE
        L{http.urlparse} should reject unicode input early.
        zhttp://example.org/pathN)rY�	TypeErrorr r
rEs r4�test_urlparseRejectsUnicodez/QueryArgumentsTests.test_urlparseRejectsUnicode�
s��	
���)�T�]�]�4M�Nr3N)r.r/r0rlror2r3r4rZrZ�
s��K*�ZOr3rZc��eZdZd�Zy)�ClientDriverc�.�||_||_||_yr7)ryr�rzrxs    r4r�zClientDriver.handleStatus�
s����������r3N)r.r/r0r�r2r3r4rqrq�
s��r3rqc��eZdZd�Zd�Zd�Zy)�ClientStatusParsingTestsc���t�}|jd�|j|jd�|j|jd�|j|j
d�y)NsHTTP/1.0 201 foort�201r��rq�lineReceivedrQryr�rz�rFr[s  r4�testBaselinez%ClientStatusParsingTests.testBaselinesR���N��	���*�+�������K�0�������6�*�������F�+r3c���t�}|jd�|j|jd�|j|jd�|j|j
d�y)N�HTTP/1.0 201rtrvr3rwrys  r4�
testNoMessagez&ClientStatusParsingTests.testNoMessagesQ���N��	����'�������K�0�������6�*�������C�(r3c���t�}|jd�|j|jd�|j|jd�|j|j
d�y)Ns
HTTP/1.0 201 rtrvr3rwrys  r4�testNoMessage_trailingSpacez4ClientStatusParsingTests.testNoMessage_trailingSpacesR���N��	���'�(�������K�0�������6�*�������C�(r3N)r.r/r0rzr}rr2r3r4rtrt�
s��,�)�)r3rtc���eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d �Z"d!�Z#d"�Z$d#�Z%d$�Z&d%�Z'd&�Z(d'�Z)d(�Z*d)�Z+d*�Z,d+�Z-d,�Z.d-�Z/d.�Z0d/�Z1d0�Z2d1�Z3d2�Z4d3�Z5d4�Z6d5�Z7d6�Z8d7�Z9d8�Z:d9�Z;d:�Z<d;�Z=d<�Z>d=�Z?d>�Z@d?�ZAd@�ZBdA�ZCdB�ZDdC�ZEdD�ZFdE�ZGdF�ZHdG�ZIdH�ZJdI�ZKdJ�ZLdK�ZMyL)M�RequestTestsz#
    Tests for L{http.Request}
    c��tjt�d�}t||�j	ddg�|jt||�dd�t
||ddi�|jtt||�j��ddgfg�t
||tj��|jt||�i�y)a0
        Verify that each of two different attributes which are associated with
        the same state properly reflect changes made through the other.

        This is used to test that the C{headers}/C{responseHeaders} and
        C{received_headers}/C{requestHeaders} pairs interact properly.
        Fr^r_r�r�raN)r r+r&�getattrr�rQ�setattrr�r�r!�Headers)rF�oldName�newNamer2s    r4�_compatHeadersTestzRequestTests._compatHeadersTests����l�l�<�>�5�1����W��+�+�G�h�Z�@������g�.�w�7��B���W�v�v�.�/�������g�&�7�7�9�:�f�v�h�=O�<P�	
�	��W�l�2�2�4�5������g�.��3r3c��tjt�d�}|jj	ddg�|j|j
d�d�y)zb
        L{http.Request.getHeader} returns the value of the named request
        header.
        Fr^r_N�r r+r&r�r�rQrq�rFr2s  r4�test_getHeaderzRequestTests.test_getHeader-sG��
�l�l�<�>�5�1�����(�(��8�*�=�������w�/��:r3c�����tjt�d����fd�}|dd�|dd�|dd�|dd�|dd�|d	d
�|dd�|d
d�|dd�y)z�
        L{http.Request.getRequestHostname} returns the hostname portion of the
        request, based on the C{Host:} header.
        Fc����jjd|g��j�j�|�y)N�host)r�r�rQ�getRequestHostname)rk�expectedHostr2rFs  ��r4�checkz3RequestTests.test_getRequestHostname.<locals>.check=s4������,�,�W�v�h�?����S�3�3�5�|�Dr3r]sexample.com:8443s192.168.1.1s192.168.1.1:19289s[2607:f0d0:1002:51::4]s2607:f0d0:1002:51::4s)[2607:f0d0:1002:0051:0000:0000:0000:0004]s'2607:f0d0:1002:0051:0000:0000:0000:0004s[::1]s::1s
[::1]:8080s[2607:f0d0:1002:51::4]:9443N)r r+r&)rFr�r2s` @r4�test_getRequestHostnamez$RequestTests.test_getRequestHostname6s����
�l�l�<�>�5�1��	E�	�n�n�-�
�!�>�2�
�n�n�-�
�"�N�3�
�'�)@�A�
�8�6�	
�	�h���
�m�V�$�
�,�.E�Fr3c��tjt�d�}|jj	dddg�|j|j
d�d�y)z�
        When there are multiple values for a single request header,
        L{http.Request.getHeader} returns the last value.
        Fr^r_�pandaNr�r�s  r4�test_getHeaderReceivedMultiplesz,RequestTests.test_getHeaderReceivedMultiplesNsJ��
�l�l�<�>�5�1�����(�(��8�X�2F�G�������w�/��:r3c��tjt�d�}|j|j	d�d�y)z�
        L{http.Request.getHeader} returns L{None} when asked for the value of a
        request header which is not present.
        Fr^N)r r+r&rQrqr�s  r4�test_getHeaderNotFoundz#RequestTests.test_getHeaderNotFoundWs/��
�l�l�<�>�5�1��������w�/��6r3c��tjt�d�}|jj	ddg�|j|j
�ddi�y)z�
        L{http.Request.getAllheaders} returns a C{dict} mapping all request
        header names to their corresponding values.
        Fr^r_N�r r+r&r�r�rQ�
getAllHeadersr�s  r4�test_getAllHeaderszRequestTests.test_getAllHeaders_sL��
�l�l�<�>�5�1�����(�(��8�*�=�����*�*�,�w��.A�Br3c��tjt�d�}|j|j	�i�y)zq
        L{http.Request.getAllHeaders} returns an empty C{dict} if there are no
        request headers.
        FN)r r+r&rQr�r�s  r4�test_getAllHeadersNoHeadersz(RequestTests.test_getAllHeadersNoHeadershs/��
�l�l�<�>�5�1������*�*�,�b�1r3c��tjt�d�}|jj	dddg�|j|j
�ddi�y)z�
        When there are multiple values for a single request header,
        L{http.Request.getAllHeaders} returns only the last value.
        Fr^r_r�Nr�r�s  r4�!test_getAllHeadersMultipleHeadersz.RequestTests.test_getAllHeadersMultipleHeaderspsO��
�l�l�<�>�5�1�����(�(��8�X�2F�G�����*�*�,�w��.A�Br3c��t�}tj|d�}|jd�|j	d�|j|jjj�j�dd�y)z~
        L{http.Request.setResponseCode} takes a status code and causes it to be
        used as the response status.
        F��r3rs (no clientproto yet) 201 CreatedN�
r&r r+rCryrQr��written�getvaluer��rFr�r2s   r4�test_setResponseCodez!RequestTests.test_setResponseCodeysk��
�.���l�l�7�E�*�����C� ��	�	�#��������%�%�.�.�0�;�;�=�a�@�/�	
r3c��t�}tj|d�}|jdd�|j	d�|j|jjj�j�dd�y)z�
        L{http.Request.setResponseCode} takes a status code and a message and
        causes them to be used as the response status.
        F��shappily acceptedr3rs)(no clientproto yet) 202 happily acceptedNr�r�s   r4�test_setResponseCodeAndMessagez+RequestTests.test_setResponseCodeAndMessage�sn��
�.���l�l�7�E�*�����C�!4�5��	�	�#��������%�%�.�.�0�;�;�=�a�@�8�	
r3c��t�}tj|d�}|jt|j
dd�y)z�
        L{http.Request.setResponseCode} accepts C{bytes} for the message
        parameter and raises L{TypeError} if passed anything else.
        Fr�znot happily acceptedN)r&r r+rYrnrCr�s   r4�&test_setResponseCodeAndMessageNotBytesz3RequestTests.test_setResponseCodeAndMessageNotBytes�s6��
�.���l�l�7�E�*�����)�S�%8�%8�#�?U�Vr3c��tjt�d�}|jd�|j	t
|jd�y)z�
        L{http.Request.setResponseCode} accepts C{int} for the code parameter
        and raises L{TypeError} if passed anything else.
        Fr*�1N)r r+r&rCrYrnr�s  r4�#test_setResponseCodeAcceptsIntegersz0RequestTests.test_setResponseCodeAcceptsIntegers�s<��
�l�l�<�>�5�1�����A�����)�S�%8�%8�#�>r3c�b�tjt�d�}|jd�y)z`
        L{http.Request.setResponseCode} accepts L{int} for the code
        parameter.
        Fr*N)r r+r&rCr�s  r4�'test_setResponseCodeAcceptsLongIntegersz4RequestTests.test_setResponseCodeAcceptsLongIntegers�s$��
�l�l�<�>�5�1�����A�r3c��tjt�d�}|jd�|j	|j
d�y)z�
        When no previous value was set and no 'if-modified-since' value was
        requested, L{http.Request.setLastModified} takes a timestamp in seconds
        since the epoch and sets the request's lastModified attribute.
        F�*N�r r+r&�setLastModifiedrQ�lastModifiedr�s  r4�test_setLastModifiedNeverSetz)RequestTests.test_setLastModifiedNeverSet�s:���l�l�<�>�5�1�����B������)�)�2�.r3c��tjt�d�}|jd�|jd�|j	|j
d�y)z�
        If the supplied timestamp is later than the lastModified attribute's
        value, L{http.Request.setLastModified} updates the lastModifed
        attribute.
        Frr*Nr�r�s  r4�test_setLastModifiedUpdatez'RequestTests.test_setLastModifiedUpdate�sH���l�l�<�>�5�1�����A�����A������)�)�1�-r3c��tjt�d�}|jd�|jd�|j	|j
d�y)z�
        If the supplied timestamp occurs earlier than the current lastModified
        attribute, L{http.Request.setLastModified} ignores it.
        Fr*rNr�r�s  r4�test_setLastModifiedIgnorez'RequestTests.test_setLastModifiedIgnore�sH��
�l�l�<�>�5�1�����A�����A������)�)�1�-r3c���tjt�d�}|jj	td�dg�|j
d�}|j|tj�y)z�
        If the resource is older than the if-modified-since date in the request
        header, L{http.Request.setLastModified} returns L{http.CACHED}.
        F�if-modified-sinces02 Jan 1970 00:00:00 GMTr�N�	r r+r&r�r�rr�rQ�CACHED�rFr2rYs   r4�test_setLastModifiedCachedz'RequestTests.test_setLastModifiedCached�s_��
�l�l�<�>�5�1�����(�(��-�.�1L�0M�	
��$�$�R�(���������-r3c���tjt�d�}|jj	td�dg�|j
d�}|j|d�y)z�
        If the resource is newer than the if-modified-since date in the request
        header, L{http.Request.setLastModified} returns None
        Fr�s01 Jan 1970 00:00:00 GMT�@BN�r r+r&r�r�rr�rQr�s   r4�test_setLastModifiedNotCachedz*RequestTests.test_setLastModifiedNotCached�s[��
�l�l�<�>�5�1�����(�(��-�.�1L�0M�	
��$�$�W�-�������&r3c���tjt�d�}|jj	td�dg�|j
d�|j
d�}|j|d�y)z�
        When L{http.Request.setLastModified} is called multiple times, the
        highest supplied value is honored. If that value is higher than the
        if-modified-since date in the request header, the method returns None.
        Fr�s01 Jan 1970 00:00:01 GMTr�rNr�r�s   r4�"test_setLastModifiedTwiceNotCachedz/RequestTests.test_setLastModifiedTwiceNotCached�si���l�l�<�>�5�1�����(�(��-�.�1L�0M�	
�	���G�$��$�$�Q�'�������&r3c��tjt�d�}|jj	td�dg�|j
d�|j
d�}|j|tj�y)a
        When L{http.Request.setLastModified} is called multiple times, the
        highest supplied value is honored. If that value is lower than the
        if-modified-since date in the request header, the method returns
        L{http.CACHED}.
        Fr�s01 Jan 1999 00:00:01 GMTr*rNr�r�s   r4�test_setLastModifiedTwiceCachedz,RequestTests.test_setLastModifiedTwiceCachedsm���l�l�<�>�5�1�����(�(��-�.�1L�0M�	
�	���A���$�$�Q�'���������-r3c��tjt�d�}|jdd�|j	|j
j
d�dg�y)��
        L{http.Request.setHost} sets the value of the host request header.
        The port should not be added because it is the default.
        Fr]�Pr�N�r r+r&�setHostrQr�r�r�s  r4�test_setHostzRequestTests.test_setHostsH��
�l�l�<�>�5�1�����N�B�'�����+�+�9�9�'�B�^�DT�Ur3c���t�}tj�|_tj|d�}|jdd�|j
|jjd�dg�y)r�Fr]i�r�N�	r&r/r�r r+r�rQr�r��rFr�r2s   r4�test_setHostSSLzRequestTests.test_setHostSSLs]��

�N��"�&�&�(����l�l�1�e�$�����N�C�(�����+�+�9�9�'�B�^�DT�Ur3c��tjt�d�}|jdd�|j	|j
j
d�dg�y�z�
        L{http.Request.setHost} sets the value of the host request header.
        The port should be added because it is not the default.
        Fr]�Qr�sexample.com:81Nr�r�s  r4�test_setHostNonDefaultPortz'RequestTests.test_setHostNonDefaultPort%sI��
�l�l�<�>�5�1�����N�B�'�����+�+�9�9�'�B�EV�DW�Xr3c���t�}tj�|_tj|d�}|jdd�|j
|jjd�dg�yr�r�r�s   r4�test_setHostSSLNonDefaultPortz*RequestTests.test_setHostSSLNonDefaultPort.s^��

�N��"�&�&�(����l�l�1�e�$�����N�B�'�����+�+�9�9�'�B�EV�DW�Xr3c��tjt�d�}|jdd�|j	|j
j
d�dg�y)zX
        L{http.Request.setHeader} sets the value of the given response header.
        Fr^r_N)r r+r&rtrQr�r�r�s  r4�test_setHeaderzRequestTests.test_setHeader9sG���l�l�<�>�5�1���
�
�g�x�(�����,�,�:�:�7�C�h�Z�Pr3c���t�}tj|d�}|j|i|��|j	|j
d|�|j
d�|jjj�jd�}|D�cgc]}|jd�s�|��}}|j	t|�d�|j	|dd|z�ycc}w)	z�
        Call L{http.Request.addCookie} with C{*args} and C{**kwargs}, and check
        that the cookie value is equal to C{expectedCookieValue}.
        Frr3r�s
Set-Cookier*sSet-Cookie: N)
r&r r+�	addCookierQr�ryr�r�r�r��
startswithrx)	rF�expectedCookieValuer8r9r�r2�writtenLinesr�addCookieLiness	         r4�_checkCookiezRequestTests._checkCookieAs���
�.���l�l�7�E�*����
�
�t�&�v�&�������Q��)<�=�	�	�	�#���(�(�0�0�9�9�;�A�A�'�J��&2�Q��Q�\�\�-�5P�!�Q��Q�����^�,�a�0������*�O�>Q�,Q�R��Rs�C+�1C+c�.�d}|j|dd�y)z�
        L{http.Request.addCookie} adds a new cookie to be sent with the
        response, and can be called with just a key and a value. L{unicode}
        arguments are encoded using UTF-8.
        �foo=bar�foo�barN�r��rFr�s  r4�)test_addCookieWithMinimumArgumentsUnicodez6RequestTests.test_addCookieWithMinimumArgumentsUnicodeTs��)�����-�u�e�<r3c�>�d}|j|dddddddd	d	�
�
y)z�
        L{http.Request.addCookie} adds a new cookie to be sent with the
        response. L{unicode} arguments are encoded using UTF-8.
        �}foo=bar; Expires=Fri, 31 Dec 9999 23:59:59 GMT; Domain=.example.com; Path=/; Max-Age=31536000; Comment=test; Secure; HttpOnlyr�r�zFri, 31 Dec 9999 23:59:59 GMTz.example.com�/�31536000�testT��expires�domainr�max_age�comment�secure�httpOnlyNr�r�s  r4�%test_addCookieWithAllArgumentsUnicodez2RequestTests.test_addCookieWithAllArgumentsUnicode^s?��
.�	�	
������3�!������	�	
r3c�.�d}|j|dd�y)z�
        L{http.Request.addCookie} adds a new cookie to be sent with the
        response, and can be called with just a key and a value. L{bytes}
        arguments are not decoded.
        r�r�r�Nr�r�s  r4�'test_addCookieWithMinimumArgumentsBytesz4RequestTests.test_addCookieWithMinimumArgumentsBytesvs��)�����-�v�v�>r3c�>�d}|j|dddddddd	d	�
�
y)z�
        L{http.Request.addCookie} adds a new cookie to be sent with the
        response. L{bytes} arguments are not decoded.
        r�r�r�sFri, 31 Dec 9999 23:59:59 GMTs.example.comr's31536000r^Tr�Nr�r�s  r4�#test_addCookieWithAllArgumentsBytesz0RequestTests.test_addCookieWithAllArgumentsBytes�s?��
.�	�	
������4�"������	�	
r3c	�J�d�}gd�}ttttzt	t
g���}ddgddgg}|D]a\}}|j
|||�||�|D]=\}}dj|||�|||�g�}|j|||fi||i���?�cy)zq
        L{http.Request.addCookie} replaces linear whitespace and
        semicolons with single spaces.
        c�(�dj||g�S)N�=)rS)r�r�s  r4�cookieValuez<RequestTests.test_addCookieSanitization.<locals>.cookieValue�s���9�9�c�5�\�*�*r3))r�sExpires)r�sDomain)rsPath)r�sMax-Age)r�sCommentzFoo; barsFoo  barsFoo; bars; N)r��zipr)r'rr(r�rS)	rFr��	arguments�inputsAndOutputs�
inputValue�outputValue�argument�	parameterr�s	         r4�test_addCookieSanitizationz'RequestTests.test_addCookieSanitization�s���	+�
�	� ��.�1P�P��~�&�'�
�
����%�
�+�&�
��
(8�
	�#�J������K��5�z�:�
�(1�	
�#��)� �:�:�#�K��=�#�I�{�;����"��!�!��j�*��9A�:�8N��	
�	
	r3c���|jdddd��|jdddd��|jdddd��|jt|jd	ddd
��y)zL
        L{http.Request.setCookie} supports a C{sameSite} argument.
        sfoo=bar; SameSite=laxr�r��lax)�sameSite�Laxsfoo=bar; SameSite=strict�strictr3z
anything-elseN)r�rYrZrEs r4�test_addCookieSameSitez#RequestTests.test_addCookieSameSite�sx��	
���2�F�F�U��S����2�F�F�U��S����'���(�	�	
�	
�����)�)�3����	�	
r3c�4�t�}tj|d�}t�}||_|jd�d|_|jjddg�|jd�|j|j�dg�y)	z�
        For an HTTP 1.0 request, L{http.Request.write} sends an HTTP 1.0
        Response-Line and whatever response headers are set.
        FrArtr^r_r`)r�rcr`N�r&r r+rr�rCrwr�r�ryr�r��rFr�r2res    r4�test_firstWritezRequestTests.test_firstWrite�s���
�.���l�l�7�E�*���!��!������C� �%������)�)�'�H�:�>��	�	�(���!�!��K�K�M�J�K�	
r3c�V�t�}tj|d�}t�}||_|jd�d|_|jjddg�|jd�|jd�|j|j�dg�y	)
z�
        For an HTTP 1.1 request, L{http.Request.write} sends an HTTP 1.1
        Response-Line, whatever response headers are set, and uses chunked
        encoding for the response body.
        FrAr�r^r_r`rarbNrrs    r4�test_firstWriteHTTP11Chunkedz)RequestTests.test_firstWriteHTTP11Chunked�s����.���l�l�7�E�*���!��!������C� �%������)�)�'�H�:�>��	�	�(���	�	�)���!�!��K�K�M��
�
	
r3c�B�t�}tj|d�}t�}||_|jd�d|_d|_|jjddg�|jd�|j|j�dg�y	)
z�
        For an HTTP 1.0 request for a resource with a known last modified time,
        L{http.Request.write} sends an HTTP Response-Line, whatever response
        headers are set, and a last-modified header with that time.
        FrArtrr^r_r`)r�rc�,Last-Modified: Thu, 01 Jan 1970 00:00:00 GMTr`N)
r&r r+rr�rCrwr�r�r�ryr�r�rs    r4�test_firstWriteLastModifiedz(RequestTests.test_firstWriteLastModified
s����.���l�l�7�E�*���!��!������C� �%���������)�)�'�H�:�>��	�	�(���!�!��K�K�M��
�
	
r3c���tj|t�}t�}t	j
|d�}t
�}||_|jd�d|_	d|_
|jjddg�|jd�|j|j�dg�|j!d	t#|��|d
}|j!d|d�y
)z�
        If the last-modified header already exists in the L{http.Request}
        response headers, the lastModified attribute is ignored and a message
        is logged.
        FrArtiʚ;s
last-modifiedsThu, 01 Jan 1970 00:00:00 GMTr`)r�rr`r*rzPWarning: last-modified specified both in header list and lastModified attribute.r�N)rr�rr&r r+rr�rCrwr�r�r�ryr�r�r�rx)rFr�r�r2rer�s      r4�test_lastModifiedAlreadyWrittenz,RequestTests.test_lastModifiedAlreadyWritten"
s���+�<�<�T�CU�V���.���l�l�7�E�*���!��!������C� �%���%������)�)��?�@�	
�	�	�	�(���!�!��K�K�M��
�		
�	
���!�S��-�.��A������
7��,��	
r3c�x�tjt�d�}|j|ji�y)zP
        L{http.Request.received_cookies} defaults to an empty L{dict}.
        FN)r r+r&rQ�received_cookiesr�s  r4�test_receivedCookiesDefaultz(RequestTests.test_receivedCookiesDefaultI
s,���l�l�<�>�5�1������-�-�r�2r3c���tjt�d�}|jj	ddg�|j�|j
|jddd��y)z�
        L{http.Request.parseCookies} extracts cookies from C{requestHeaders}
        and adds them to C{received_cookies}.
        F�cookiestest="lemur"; test2="panda"�"lemur"�"panda"�r^stest2N�r r+r&r�r��parseCookiesrQrr�s  r4�test_parseCookieszRequestTests.test_parseCookiesP
sZ��
�l�l�<�>�5�1�����(�(��5S�4T�U��������� � �J�*�"M�	
r3c���tjt�d�}|jj	dddg�|j�|j
|jddd��y)	zh
        L{http.Request.parseCookies} can extract cookies from multiple Cookie
        headers.
        Frstest="lemur"s
test2="panda"rrrNr r�s  r4� test_parseCookiesMultipleHeadersz-RequestTests.test_parseCookiesMultipleHeaders\
s\��
�l�l�<�>�5�1�����(�(��_�FV�4W�X��������� � �J�*�"M�	
r3c��tjt�d�}|j�|j	|j
i�y)zj
        L{http.Request.parseCookies} can be called on a request without a
        cookie header.
        FN)r r+r&r!rQrr�s  r4�test_parseCookiesNoCookiez&RequestTests.test_parseCookiesNoCookieh
s8��
�l�l�<�>�5�1����������-�-�r�2r3c���tjt�d�}|jj	dg�|j�|j
|ji�y)zn
        L{http.Request.parseCookies} can be called on a request with an
        empty cookie header.
        FrNr r�s  r4�test_parseCookiesEmptyCookiez)RequestTests.test_parseCookiesEmptyCookieq
sN��
�l�l�<�>�5�1�����(�(��B�7���������-�-�r�2r3c���tjt�d�}|jj	ddg�|j�|j
|ji�y)z`
        L{http.Request.parseCookies} ignores cookies which don't have a
        value.
        Frsfoo; bar; baz;Nr r�s  r4� test_parseCookiesIgnoreValuelessz-RequestTests.test_parseCookiesIgnoreValueless{
sR��
�l�l�<�>�5�1�����(�(��5F�4G�H���������-�-�r�2r3c���tjt�d�}|jj	ddg�|j�|j
|jddi�y)zR
        L{http.Request.parseCookies} parses cookies with an empty value.
        Frsfoo=r�r3Nr r�s  r4�test_parseCookiesEmptyValuez(RequestTests.test_parseCookiesEmptyValue�
sT���l�l�<�>�5�1�����(�(��W�I�>���������-�-���}�=r3c���tjt�d�}|jj	ddg�|j�|j
|jddi�y)zf
        L{http.Request.parseCookies} leaves trailing whitespace in the
        cookie value.
        Frsfoo=bar r�sbar Nr r�s  r4�!test_parseCookiesRetainRightSpacez.RequestTests.test_parseCookiesRetainRightSpace�
sU��
�l�l�<�>�5�1�����(�(��[�M�B���������-�-���/@�Ar3c���tjt�d�}|jj	ddg�|j�|j
|jddi�y)zc
        L{http.Request.parseCookies} strips leading whitespace in the
        cookie key.
        Frs foo=barr�r�Nr r�s  r4�test_parseCookiesStripLeftSpacez,RequestTests.test_parseCookiesStripLeftSpace�
sU��
�l�l�<�>�5�1�����(�(��[�M�B���������-�-���/?�@r3c���tjt�d�}|jj	ddg�|j�|j
|jddd��y)zr
        L{http.Request.parseCookies} parses valid cookies set before or
        after malformed cookies.
        Frs012345; test="lemur"; 12345; test2="panda"; 12345rrrNr r�s  r4�-test_parseCookiesContinueAfterMalformedCookiez:RequestTests.test_parseCookiesContinueAfterMalformedCookie�
s_��
�l�l�<�>�5�1�����(�(��K�L�	
�	�������� � �J�*�"M�	
r3c�P�tjt�d�}|jd�|j}|jd�|j
ttd���|j|j�|j|jd�y)z�
        L{http.Request.connectionLost} closes L{Request.content} and drops the
        reference to the L{HTTPChannel} to assist with garbage collection.
        Fr�r,�FinishedN)
r r+r&�	gotLengthrn�handleContentChunkr�rrr��closedr�r�)rFr2rns   r4�test_connectionLostz RequestTests.test_connectionLost�
s}��
�l�l�<�>�5�1��	�
�
�b���+�+��	���x�(�	���7�>�*�#=�>�?�������'����S�[�[�$�/r3c���tjt�d�}|jt	�d�|jt|jt	�d�y)zv
        Calling L{Request.registerProducer} when a producer is already
        registered raises ValueError.
        FTN)r r+r&rDrrYrZr�s  r4�test_registerProducerTwiceFailsz,RequestTests.test_registerProducerTwiceFails�
sD��
�l�l�<�>�5�1�����]�_�d�3����*�c�&:�&:�M�O�T�Rr3c���tjt�d�}t�}|j	|d�|j|dfg|jj�y)z�
        Calling L{Request.registerProducer} with an IPushProducer when the
        request is not queued registers the producer as a push producer on the
        request's transport.
        FTN�r r+r&rrDrQr��	producers�rFr2rls   r4�7test_registerProducerWhenNotQueuedRegistersPushProducerzDRequestTests.test_registerProducerWhenNotQueuedRegistersPushProducer�
sO���l�l�<�>�5�1�� �?�����X�t�,����8�T�*�+�S�]�]�-D�-D�Er3c���tjt�d�}t�}|j	|d�|j|dfg|jj�y)z�
        Calling L{Request.registerProducer} with an IPullProducer when the
        request is not queued registers the producer as a pull producer on the
        request's transport.
        FNr<r>s   r4�7test_registerProducerWhenNotQueuedRegistersPullProducerzDRequestTests.test_registerProducerWhenNotQueuedRegistersPullProducer�
sO���l�l�<�>�5�1�� �?�����X�u�-����8�U�+�,�c�m�m�.E�.E�Fr3c��t�}tj|d�}|j�}|j	tt
d���|j|jd�|j|t�S)z
        L{Request.connectionLost} triggers all finish notification Deferreds
        and cleans up per-request state.
        TzConnection doneN)
r&r r+�notifyFinishr�rrr�r��
assertFailure)rFr�r}r�s    r4�test_connectionLostNotificationz,RequestTests.test_connectionLostNotification�
si��

�N���,�,�q�$�'���'�'�)�����w�~�6G�'H�I�J����W�_�_�d�3��!�!�(�N�;�;r3c��tjt�d�}|j�}|j	d�|j�|S)zO
        L{Request.finish} triggers all finish notification Deferreds.
        Fr*)r r+r&rCr5rz�rFr}r�s   r4�test_finishNotificationz$RequestTests.test_finishNotification�
sC���,�,�|�~�u�5���'�'�)��	���!�������r3c��tjt�d�}|j�}|j	d�|jd�|j
�|jt|j
d�|S)z�
        Calling L{Request.write} after L{Request.finish} has been called results
        in a L{RuntimeError} being raised.
        Fr*�foobar)	r r+r&rCr5ryrzrYr�rGs   r4�test_writeAfterFinishz"RequestTests.test_writeAfterFinish�
se��
�,�,�|�~�u�5���'�'�)��	���!���
�
�i� ��������,��
�
�y�A��r3c���t�}tj|d�}|jt	td���|j
t|j�y)z�
        Calling L{Request.finish} after L{Request.connectionLost} has been
        called results in a L{RuntimeError} being raised.
        F�The end.N)	r&r r+r�rrrYr�rzr�s   r4�test_finishAfterConnectionLostz+RequestTests.test_finishAfterConnectionLostsG��
�.���l�l�7�E�*�����7�>�*�#=�>�?����,��
�
�3r3c���t�}tj|d�}|jt	td���|j
d�|jt|j�y)z�
        Calling L{Request.write} after L{Request.connectionLost} has been
        called does not raise an exception. L{RuntimeError} will be raised
        when finish is called on the request.
        FrMrJN)
r&r r+r�rrryrYr�rzr�s   r4�test_writeAfterConnectionLostz*RequestTests.test_writeAfterConnectionLostsS���.���l�l�7�E�*�����7�>�*�#=�>�?��	�	�)�����,��
�
�3r3c��tjt�d�}|jt	|�dt|�fz�y)z�
        L{Request.__repr__} returns the class name, object address, and
        dummy-place holder values when used on a L{Request} which has not yet
        been initialized.
        FzZ<Request at 0x%x method=(no method yet) uri=(no uri yet) clientproto=(no clientproto yet)>N�r r+r&rQ�repr�id�rFr}s  r4�test_reprUninitializedz#RequestTests.test_reprUninitialized!s?���,�,�|�~�u�5�������M�
0�35�g�;�.�
A�	
r3c��tjt�d�}d|_d|_d|_|j
t|�dt|�fz�y)a
        L{Request.__repr__} returns, as a L{str}, the class name, object
        address, and the method, uri, and client protocol of the HTTP request
        it represents.  The string is in the form::

          <Request at ADDRESS method=METHOD uri=URI clientproto=PROTOCOL>
        Frtr�r�z><Request at 0x%x method=GET uri=/foo/bar clientproto=HTTP/1.0>N)	r r+r&rwrvrurQrSrTrUs  r4�test_reprInitializedz!RequestTests.test_reprInitialized.sT���,�,�|�~�u�5��)������!��������M�
$�')�'�{�n�
5�	
r3c��Gd�dtj�}|t�d�}|jt	|�dt|�fz�y)z�
        Subclasses of L{Request} inherit a C{__repr__} implementation which
        includes the subclass's name in place of the string C{"Request"}.
        c��eZdZy)�1RequestTests.test_reprSubclass.<locals>.OtherwiseN)r.r/r0r2r3r4�	Otherwiser[Fs��r3r\Fz\<Otherwise at 0x%x method=(no method yet) uri=(no uri yet) clientproto=(no clientproto yet)>NrR)rFr\r}s   r4�test_reprSubclasszRequestTests.test_reprSubclass@sK��	����	��L�N�E�2�������M�
0�35�g�;�.�
A�	
r3c��tjt�d�}t�|_|jt
�d�|j�|jd|j|jjf�y)z�
        L{Request.unregisterProducer} unregisters a non-queued non-streaming
        producer from the request and the request's transport.
        F�NNN�
r r+r&rr�rDr�unregisterProducerrQrlr�s  r4�,test_unregisterNonQueuedNonStreamingProducerz9RequestTests.test_unregisterNonQueuedNonStreamingProducerPsa��
�l�l�<�>�5�1��'�)��
����]�_�e�4���� ��������c�m�m�6L�6L�'M�Nr3c��tjt�d�}t�|_|jt
�d�|j�|jd|j|jjf�y)z�
        L{Request.unregisterProducer} unregisters a non-queued streaming
        producer from the request and the request's transport.
        FTr_Nr`r�s  r4�)test_unregisterNonQueuedStreamingProducerz6RequestTests.test_unregisterNonQueuedStreamingProducer[sa��
�l�l�<�>�5�1��'�)��
����]�_�d�3���� ��������c�m�m�6L�6L�'M�Nr3c���tj�}d|_d|_d|_|j�t
�|_|jd�}ddg}t�}|j|�|D]}|j|��|jjdj�|jd|jj!��y)zj
        L{http.Request.finish} will call the channel's factory to produce a log
        message.
        N�sometimeT�GET /path HTTP/1.1
r�rssometime "GET /path HTTP/1.1")r r�r��_logDateTime�_logDateTimeCall�startFactoryr�logFiler�rr�r�r�r�rzr�r��rFr��proto�valrers      r4�test_finishProducesLogz#RequestTests.test_finishProducesLogfs���
�"�"�$�����)���#'�� �����!�)����%�%�d�+��(�+�6���!��
���U�#��	"�A����q�!�	"�	������"�)�)�+�	
�
�
�6����8P�8P�8R�Sr3c���t�}tjd|��}|j�|j	d�}t�}t
||�}|j|jd�|j|�|jd�|jd�|j|j�|jd�|j|j�y)z�
        L{HTTPChannel} timeouts whenever data from a request body is not
        delivered to it in time, even when it gets built from a L{HTTPFactory}.
        r�)�timeoutr�Nr�r�r�)rr r�rjr�rr�rQr�r�r�r�r�r�r�rhs     r4�"test_requestBodyTimeoutFromFactoryz/RequestTests.test_requestBodyTimeoutFromFactory�s���
����"�"�3��>�������(�(��.��#�%�	�*�8�U�;��	
����)�)�3�/����	�*����M�N�
�
�
�b������0�0�1�
�
�
�a�����	�/�/�0r3c�^�tj�}d|_d|_d|_|j�t
�|_|jd�}d|j_
ddg}t�}|j|�|j|jd�|D]}|j|��|jd�|j|jd	�|jj dj#�|j|jd�y)
z�
        L{http.Request.finish} will notify the channel that it is finished, and
        will put the transport back in the producing state so that the reactor
        can close the connection.
        NrfTrrgr�rsGET r)r r�r�rhrirjrrkr�r�rrr�rQrr�r�rzrls      r4�test_finishCleansConnectionz(RequestTests.test_finishCleansConnection�s���"�"�$�����)���#'�� �����!�)����%�%�d�+��23����/�(�+�6���!��
���U�#�����,�,�k�:��	"�A����q�!�	"�	���7�#�����,�,�h�7�
������"�)�)�+�����,�,�k�:r3c�t�tjt�d�}ttj|�y)z�
        L{http.Request} provides
        L{http._IDeprecatedHTTPChannelToRequestInterface}, which
        defines the interface used by L{http.HTTPChannel}.
        FN)r r+r&r�)_IDeprecatedHTTPChannelToRequestInterfacer�s  r4�6test_provides_IDeprecatedHTTPChannelToRequestInterfacezCRequestTests.test_provides_IDeprecatedHTTPChannelToRequestInterface�s&���l�l�<�>�5�1���T�C�C�S�Ir3c�d�tjt�d�}|j||�y)z7
        A L{http.Request} is equal to itself.
        FN�r r+r&rQr�s  r4�test_eqzRequestTests.test_eq�s&���l�l�<�>�5�1������c�"r3c��tjt�d�}|j|tjt�d��y)zC
        A L{http.Request} is not equal to another object.
        FN)r r+r&�assertNotEqualr�s  r4�test_nezRequestTests.test_ne�s3���l�l�<�>�5�1�����C����l�n�e�!D�Er3c�V�tjt�d�}t|�y)z0
        A L{http.Request} is hashable.
        FN)r r+r&�hashr�s  r4�
test_hashablezRequestTests.test_hashable�s���l�l�<�>�5�1���S�	r3c���g�G�fd�d�}tjt�d�}|j||��|j�|g�y)z�
        A L{http.Request} on the left hand side of an equality
        comparison to an instance that is not a L{http.Request} hands
        the comparison off to that object's C{__eq__} implementation.
        c�"��eZdZdedef�fd�Zy)�8RequestTests.test_eqWithNonRequest.<locals>._NotARequest�other�returnc�(���j|�yr:r/�rFr��eqCallss  �r4�__eq__z?RequestTests.test_eqWithNonRequest.<locals>._NotARequest.__eq__��������u�%�r3N)r.r/r0�object�boolr��r�s�r4�_NotARequestr������
�F�
�t�
r3r�FNry�rFr�r2r�s   @r4�test_eqWithNonRequestz"RequestTests.test_eqWithNonRequest�sL�����	�	�
�l�l�<�>�5�1������l�n�-�����3�%�(r3c���g�G�fd�d�}tjt�d�}|j||��|j	�|g�y)z�
        A L{http.Request} on the left hand side of an inequality
        comparison to an instance that is not a L{http.Request} hands
        the comparison off to that object's C{__ne__} implementation.
        c�"��eZdZdedef�fd�Zy)�8RequestTests.test_neWithNonRequest.<locals>._NotARequestr�r�c�(���j|�yr:r/r�s  �r4�__ne__z?RequestTests.test_neWithNonRequest.<locals>._NotARequest.__ne__�r�r3N)r.r/r0r�r�r�r�s�r4r�r��r�r3r�FN)r r+r&r|rQr�s   @r4�test_neWithNonRequestz"RequestTests.test_neWithNonRequest�sL�����	�	�
�l�l�<�>�5�1�����C���0�����3�%�(r3c�|�tj|t�}tjt�d�}|j
t�d�|j�|jdt|��|d}|d}|j|jt�|jt�y)zy
        A RuntimeError is logged if a producer is still registered
        when an L{http.Request} is finished.
        FTr*rr7N)rr�rr r+r&rDrrzr�rxr8r�r�r:)rFr�r}r�r�s     r4�"test_finishProducerStillRegisteredz/RequestTests.test_finishProducerStillRegistered�s���
+�<�<�T�CU�V���,�,�|�~�u�5��� � ���$�7��������!�S��-�.��A����-� �����a�g�g�|�4����|�,r3c	��tjttjddd����}|j|j
�d�y)z}
        L{http.Request.getClientIP} returns the host part of the
        client's address when connected over IPv4.
        r5�	127.0.0.1�80��peerN�r r+r&r�IPv6AddressrQ�getClientIPrUs  r4�test_getClientIPWithIPv4z%RequestTests.test_getClientIPWithIPv4sD��
�,�,��g�1�1�%��e�L�M�
��	
����,�,�.��<r3c	��tjttjddd����}|j|j
�d�y)z}
        L{http.Request.getClientIP} returns the host part of the
        client's address when connected over IPv6.
        r5z::1r�r�Nr�rUs  r4�test_getClientIPWithIPv6z%RequestTests.test_getClientIPWithIPv6sD��
�,�,��g�1�1�%���F�G�
��	
����,�,�.��6r3c��tjttjd����}|j|j
�d�y)z�
        L{http.Request.getClientIP} returns L{None} for the client's
        IP address when connected over a non-TCP transport.
        �/path/to/socketr�N)r r+r&r�UNIXAddressrQr�rUs  r4�test_getClientIPWithNonTCPPeerz+RequestTests.test_getClientIPWithNonTCPPeersA��
�,�,��g�1�1�2C�D�E�
��	
����,�,�.��5r3c��tjd�}tjt	|���}|j|j
�|�y)zs
        L{http.Request.getClientAddress} returns the client's address
        as an L{IAddress} provider.
        r�r�N)rr�r r+r&rk�getClientAddress)rFr�r}s   r4�test_getClientAddressz"RequestTests.test_getClientAddress$s?��
�$�$�%6�7���,�,�|��8�9���
�
�g�.�.�0�&�9r3N)Nr.r/r0r1r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrr"r$r&r(r*r,r.r0r2r8r:r?rArErHrKrNrPrVrXr]rbrdrorrrtrwrzr}r�r�r�r�r�r�r�r�r2r3r4r�r�s����4�$;�G�0;�7�C�2�C�
�
�W�?��
/�.�
.�.�'�'� .�"V�	V�Y�	Y�Q�S�&=�
�0?�
�0*�X
�
�(
�<
�<%
�N3�

�

�3�3�3�>�B�A�
�0�*S�	F�	G�
<�
�
�4�
4�
�
�$
� 	O�	O�T�41�,;�>J�#�F��)�$)�$
-�=�7�6�:r3r�c�@�eZdZdZd�Zdddd�Zd�Zd�Zd	�Zd
�Z	d�Z
y)
�MultilineHeadersTestsa
    Tests to exercise handling of multiline headers by L{HTTPClient}.  RFCs 1945
    (HTTP 1.0) and 2616 (HTTP 1.1) state that HTTP message header fields can
    span multiple lines if each extra line is preceded by at least one space or
    horizontal tab.
    c� �d|_d|_y)zv
        Initialize variables used to verify that the header-processing functions
        are getting called.
        FN)�handleHeaderCalled�handleEndHeadersCalledrEs r4r�zMultilineHeadersTests.setUp6s��
#(���&+��#r3�10s
line-0	line-1s
line-2 line-3)rmsX-MultilinesX-Multiline2c�P�d|_|j||j|�y)zE
        Dummy implementation of L{HTTPClient.handleHeader}.
        TN)r�rQr�)rFr�rns   r4�ourHandleHeaderz%MultilineHeadersTests.ourHandleHeaderFs'��#'�������d�2�2�3�7�8r3c��d|_y)zI
        Dummy implementation of L{HTTPClient.handleEndHeaders}.
        TN)r�rEs r4�ourHandleEndHeadersz)MultilineHeadersTests.ourHandleEndHeadersMs��'+��#r3c�
�t�}|j|_|j|_|jd�|jd�|j
|jd�|j|j�|j|j�|jd�|j|j�|j|j�|j|jd�y)z�
        A header isn't processed by L{HTTPClient.extractHeader} until it is
        confirmed in L{HTTPClient.lineReceived} that the header has been
        received completely.
        r|�Content-Length: 10Nr3r�)
rqr�r�r�r�rxr�r|r�r�r�r�rQrys  r4�test_extractHeaderz(MultilineHeadersTests.test_extractHeaderSs���
�N���-�-���!�5�5���	����'�	���,�-����Q�X�X�t�,�����0�0�1�����4�4�5�	
���s������/�/�0�����3�3�4�������2�&r3c�|�t�}|j|_|j|_|jd�|jd�|j
|j�|j|j�|j|jd�|j|jd�y)z�
        An HTTP request with no headers will not cause any calls to
        L{handleHeader} but will cause L{handleEndHeaders} to be called on
        L{HTTPClient} subclasses.
        r|r3rtrvN)
rqr�r�r�r�rxr�r�r�r�rQryr�rys  r4�test_noHeadersz$MultilineHeadersTests.test_noHeadersjs���
�N���-�-���!�5�5���	����'�	
���s������0�0�1�����3�3�4�������K�0�������6�*r3c��t�}|j|_|j|_|jd�|jd�|j
|j�|jd�|jd�|j|j�|jd�|jd�|jd�|j|j�|j|jd�|j|jd	�|j|jd
�y)z�
        L{HTTPClient} parses multiline headers by buffering header lines until
        an empty line or a line that does not start with whitespace hits
        lineReceived, confirming that the header has been received completely.
        r|sX-Multiline: line-0s	line-1sX-Multiline2: line-2s line-3r�r3rtrvr�N)rqr�r�r�r�rxr�r�r�r�rQryr�r|rys  r4�test_multilineHeadersz+MultilineHeadersTests.test_multilineHeaders}s���
�N���-�-���!�5�5���	����'�	���-�.�����0�0�1�	���{�#�	���.�/�����/�/�0�	���z�"�	���,�-�	
���s������3�3�4�������K�0�������6�*�������2�&r3N)r.r/r0r1r�r�r�r�r�r�r�r2r3r4r�r�.s7���,�!�)�)��O�9�+�'�.+�&'r3r�c��eZdZdZd�Zd�Zy)�Expect100ContinueServerTestsai
    Test that the HTTP server handles 'Expect: 100-continue' header correctly.

    The tests in this class all assume a simplistic behavior where user code
    cannot choose to deny a request. Once ticket #288 is implemented and user
    code can run before the body of a POST is processed this should be
    extended to support overriding this behavior.
    c���t�}tj�}t|_|j|�|j
d�|j
d�|j
d�|j
d�|j
d�|j|j�d�|j
d�|j|j�dg�y	)
z�
        HTTP/1.0 requests do not get 100-continue returned, even if 'Expect:
        100-continue' is included (RFC 2616 10.1.1).
        sGET / HTTP/1.0
�Host: www.example.com
�Content-Length: 3
�Expect: 100-continue
r�r3r�)r�r�r�r�r��
'''
3
abc'''
N)
rr r�r�r�r�r�rQr�r�)rFr�r�s   r4�test_HTTP10z(Expect100ContinueServerTests.test_HTTP10�s���
$�%�	��"�"�$��!6������y�)����2�3����9�:����5�6����8�9����W�%�������*�C�0����V�$��!�!��O�O���	
�	
r3c�f�t�}tj�}t|_|j|�|j
d�|j
d�|j
d�|j
d�|j|j�d�|j
d�|j|j�d�|j
d�|j�}|j|jd��|td�d	}|j|d
g�y	)a!
        If a HTTP/1.1 client sends a 'Expect: 100-continue' header, the server
        responds with a 100 response code before handling the request body, if
        any. The normal resource rendering code will then be called, which
        will send an additional response code.
        sGET / HTTP/1.1
r�r�r�r3r�sHTTP/1.1 100 Continue

r�N)r�r�r�r�r�r�)
rr r�r�r�r�r�rQr�r�r�rxr�)rFr�r�r�s    r4�test_expect100ContinueHeaderz9Expect100ContinueServerTests.test_expect100ContinueHeader�s
��$�%�	��"�"�$��!6������y�)����2�3����9�:����8�9����5�6�	
������*�C�0����W�%�	
������*�,L�M����V�$��?�?�$������+�+�,L�M�N��C� @�A�C�D���!�!���	
�	
r3N)r.r/r0r1r�r�r2r3r4r�r��s���
�<&
r3r�c�4�|D�cic]}|||��
c}Scc}w)a�
    Create a new dict containing only a subset of the items of an existing
    dict.

    @param keys: An iterable of the keys which will be added (with values from
        C{d}) to the result.

    @param d: The existing L{dict} from which to copy items.

    @return: The new L{dict} with keys given by C{keys} and values given by the
        corresponding values in C{d}.
    @rtype: L{dict}
    r2)�keysr��ks   r4�subr��s ��"�"��A�q��t�G�"�"��"s�
c��eZdZdZd�Zd�Zy)� DeprecatedRequestAttributesTestszI
    Tests for deprecated attributes of L{twisted.web.http.Request}.
    c	��tjttjddd����}|jd�|j
ddd�|j�|j|jg�	�}|jd
t|��|jtdd�td
dg|d��y)zg
        L{Request.getClientIP} is deprecated in favor of
        L{Request.getClientAddress}.
        r5r�i90r�rr�r'r���offendingFunctionsr*zjtwisted.web.http.Request.getClientIP was deprecated in Twisted 18.4.0; please use getClientAddress instead��categoryrzr�rzN)r r+r&rr�r5�requestReceivedr��
flushWarnings�test_getClientIPrQrx�DeprecationWarningr�)rFr}�warningss   r4r�z1DeprecatedRequestAttributesTests.test_getClientIPs���
�,�,��g�1�1�%��e�L�M�
��	���!�������k�:������%�%�$�:O�:O�9P�%�Q������C��M�*����.�M�
�
��Y�'��!��5�		
r3c�"�t�}tj|�}|j�|j	|j
g��}|j
dt|��|j
tdd�tddg|d��y)	zs
        L{Request.noLongerQueued} is deprecated, as we no longer process
        requests simultaneously.
        r�r*zHtwisted.web.http.Request.noLongerQueued was deprecated in Twisted 16.3.0r�r�rzrN)
r&r r+�noLongerQueuedr��test_noLongerQueuedrQrxr�r�)rFr�r}r�s    r4r�z4DeprecatedRequestAttributesTests.test_noLongerQueueds���
�.���,�,�w�'����� ��%�%�$�:R�:R�9S�%�T������C��M�*����.�(�
�
��Y�'��!��5�		
r3N)r.r/r0r1r�r�r2r3r4r�r��s���
�4
r3r�c�b�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zy)�ChannelProductionTestsz=
    Tests for the way HTTPChannel manages backpressure.
    s#GET / HTTP/1.1
Host: localhost

c�x�|}tj�}t|�|_|j	|�||fS)a
        Setup a L{HTTPChannel} and a transport and associate them.

        @param transport: A transport to back the L{HTTPChannel}
        @param requestFactory: An object that can construct L{Request} objects.
        @return: A tuple of the channel and the transport.
        )r r�r=r�r�)rFr�r�r�s    r4�buildChannelAndTransportz/ChannelProductionTests.buildChannelAndTransport<s=���	��"�"�$��!9�.�!I������y�)��	�!�!r3c��|jt�t�\}}|j|j|�|j|j�y)zu
        L{HTTPChannel} registers itself as a producer with its transport when a
        connection is made.
        N)r�rrirQrlr��	streaming�rFr�r�s   r4�test_HTTPChannelIsAProducerz2ChannelProductionTests.test_HTTPChannelIsAProducerKsL��
"�:�:���/�
����	
����+�+�W�5����	�+�+�,r3c���|jt�t�\}}|j�|j	|j
d�|j	|jd�y)zV
        L{HTTPChannel} unregisters itself when it has loseConnection called.
        N)r�rrir'rkrlr�r�s   r4�8test_HTTPChannelUnregistersSelfWhenCallingLoseConnectionzOChannelProductionTests.test_HTTPChannelUnregistersSelfWhenCallingLoseConnectionWsX��"�:�:���/�
����	��� ��
�
�i�(�(�$�/��
�
�i�)�)�4�0r3c���|jt�t�\}}|jt	�d�|jt|jt	�d�y)z�
        If two producers are registered on a L{HTTPChannel} without the first
        being unregistered, a L{RuntimeError} is thrown.
        TN)r�rrirDrrYr�r�s   r4�(test_HTTPChannelRejectsMultipleProducersz?ChannelProductionTests.test_HTTPChannelRejectsMultipleProducerscsS��
"�:�:���/�
����	� � ���$�7����,��(@�(@�-�/�SW�Xr3c��|jt�t�\}}|j�|j	|j
d�y)zr
        If there is no producer, the L{HTTPChannel} can still have
        C{unregisterProducer} called.
        N�r�rrirark�_requestProducerr�s   r4�+test_HTTPChannelCanUnregisterWithNoProducerzBChannelProductionTests.test_HTTPChannelCanUnregisterWithNoProducero�D��
"�:�:���/�
����	�"�"�$��
�
�g�.�.��5r3c��|jt�t�\}}|j�|j	|j
d�y)zn
        If there is no request producer currently registered, C{stopProducing}
        does nothing.
        Nr�r�s   r4�,test_HTTPChannelStopWithNoRequestOutstandingzCChannelProductionTests.test_HTTPChannelStopWithNoRequestOutstanding{r�r3c�x�|jt�t�\}}|j|j�|j
dj}t�}|j|d�|j|jg�|j�|j|jdg�y)z�
        If there is a request producer registered with L{HTTPChannel}, calling
        C{stopProducing} causes that producer to be stopped as well.
        rT�stopN)r�rr�r�r}r�r�rrDrQ�events�
stopProducing�rFr�r�r}rls     r4�#test_HTTPChannelStopRequestProducerz:ChannelProductionTests.test_HTTPChannelStopRequestProducer�s���
"�:�:���1�
����
	���T�\�\�*��"�"�1�%�.�.��!�?��� � ��4�0�	
������"�-�	����������6�(�3r3c�.�|jt�t�\}}|j|jd�|j�|j|jd�|j
�|j|jd�y)z�
        When L{HTTPChannel} has C{pauseProducing} called on it by the transport
        it will call C{pauseProducing} on the transport. When unpaused, the
        L{HTTPChannel} will call C{resumeProducing} on its transport.
        rrN)r�rrirQr�pauseProducing�resumeProducingr�s   r4�;test_HTTPChannelPropagatesProducingFromTransportToTransportzRChannelProductionTests.test_HTTPChannelPropagatesProducingFromTransportToTransport�s���"�:�:���/�
����
	
����0�0�+�>�	��� �����0�0�(�;�	���!�����0�0�+�>r3c�$�|jt�t�\}}d|_|j	|j
�|j	d�|jdj}t�}|j|d�|j|jd�|j|jg�|j�|j|jd�|j|jdg�|j�|j|jd�|j|jddg�|j�|j!�|j|jd�y)	z�
        If a L{Request} object has registered itself as a producer with a
        L{HTTPChannel} object, and the L{HTTPChannel} object is paused, both
        the transport and L{Request} objects get paused.
        rs123Tr�pause�resumerN)r�rr�rr�r}r�r�rrDrQrr�r�r�rar�r�s     r4�3test_HTTPChannelPropagatesPausedProductionToRequestzJChannelProductionTests.test_HTTPChannelPropagatesPausedProductionToRequest�sP��"�:�:���1�
����,-��(�	���T�\�\�*����V�$��"�"�1�%�.�.��!�?��� � ��4�0�	
����0�0�(�;�������"�-�	��� �����0�0�(�;�������7�)�4�	���!�����0�0�(�;�������7�H�*=�>�	�"�"�$���� �����0�0�+�>r3c���|jt�t�\}}d|_|j	|j
�|j	d�|jdj}t�}|j|d�|j|jd�|j|jg�|j�|j|jd�|j|jdg�|j�|j�|j|jd�|j!�|j|jd�y)z�
        If a L{Request} object completes its response while the transport is
        paused, the L{HTTPChannel} does not resume the transport.
        rsextraTrr�rN)r�rr�rr�r}r�r�rrDrQrr�r�rar�r�r�s     r4�/test_HTTPChannelStaysPausedWhenRequestCompleteszFChannelProductionTests.test_HTTPChannelStaysPausedWhenRequestCompletes�s7��
"�:�:���1�
����,-��(�	���T�\�\�*����X�&��"�"�1�%�.�.��!�?��� � ��4�0�	
����0�0�(�;�������"�-�	��� �����0�0�(�;�������7�)�4�	�"�"�$���� �����0�0�(�;�	���!�����0�0�+�>r3c�~�Gd�dt�}|�}|j�|jt|j�|j	|�t
�\}}|j
|jd�|j�|j
|jd�|j|j�|j
|jd�|j|j�jd��|j�|j
|jd�y)z�
        If the L{HTTPChannel} has paused the transport, it still tolerates
        receiving data, and does not attempt to pause the transport again.
        c��eZdZdZd�Zy)�gChannelProductionTests.test_HTTPChannelToleratesDataWhenTransportPaused.<locals>.NoDoublePauseTransportz|
            A version of L{StringTransport} that fails tests if it is paused
            while already paused.
            c�b�|jdk(rtd��tj|�y)NrzTransport was paused twice!)rr�rr�rEs r4r�zvChannelProductionTests.test_HTTPChannelToleratesDataWhenTransportPaused.<locals>.NoDoublePauseTransport.pauseProducings*���%�%��1�&�'D�E�E��.�.�t�4r3N)r.r/r0r1r�r2r3r4�NoDoublePauseTransportr�s��
�

5r3rrrsHTTP/1.1 200 OK
N)rr�rYr�r�rirQrr�r}r�r�r�r�)rFrr�r�s    r4�0test_HTTPChannelToleratesDataWhenTransportPausedzGChannelProductionTests.test_HTTPChannelToleratesDataWhenTransportPaused
s��		5�_�		5�+�,�	�� � �"����,�	�(@�(@�A�!�:�:�"�$�&6�
����
	
����0�0�+�>�	��� �����0�0�(�;�	���T�\�\�*�	
����0�0�(�;����	���)�4�4�5K�L�M�	���!�����0�0�+�>r3c�~����jt�t�\}�t��tj�}t
|_|j��|j�j�|jdj}|jj}��fd�}|j|�S)z�
        If the L{HTTPChannel} has a L{IPullProducer} registered with it it can
        adapt that producer into an L{IPushProducer}.
        rc�t���j�jdd�d}d}�j||�y)Nr�r*s<1
0
1
1
1
2
1
3
1
4
1
5
1
6
1
7
1
8
1
9
)r�r�rQ)�ign�responseBody�expectedResponseBodyrFr�s   ��r4�validatezOChannelProductionTests.test_HTTPChannelToleratesPullProducers.<locals>.validateHs>���$�?�?�,�2�2�;��B�1�E�L�	�
!�
���\�+?�@r3)r�rr?r r��DummyPullProducerHandlerProxyr�r�r�r}r�r�rBrYr�)rFr�r}�responseCompleterr�s`    @r4�&test_HTTPChannelToleratesPullProducersz=ChannelProductionTests.test_HTTPChannelToleratesPullProducers7s����
"�:�:���7�
����$�%�	��"�"�$��!>������y�)����T�\�\�*��"�"�1�%�.�.��"�2�2�9�9��	A�  �+�+�H�5�5r3c���t�}t�}tj�}d|_|j
|_|j
|�|jd�|j|j|�|j|jd�|jd�|j|jd�|j|jd�y)zS
        L{HTTPChannel} unregisters itself when it times out a connection.
        r�r�Tr*N)rrr r�r�r�r�r�rkrlr�)rFr�r�r�s    r4�,test_HTTPChannelUnregistersSelfWhenTimingOutzCChannelProductionTests.test_HTTPChannelUnregistersSelfWhenTimingOutZs������#�%�	��"�"�$�����!�O�O������y�)�	�
�
�b���
�
�i�(�(�'�2��
�
�i�)�)�4�0�	�
�
�a���
�
�i�(�(�$�/��
�
�i�)�)�4�0r3N)r.r/r0r1r}r�r�r�r�r�r�r�r�r�r�rrr
r2r3r4r�r�5sU���C�G�
"�
-�
1�
Y�
6�
6�4�0?�**?�X(?�T+?�Z!6�F1r3r�c��eZdZdZd�Zy)�HTTPChannelSanitizationTestsz8
    Test that L{HTTPChannel} sanitizes its output.
    c	�H�tD]�}t�}tj�}|j	|�|jddd||fg��dj
ttg�dz}|j|j�dj
d|dg����y	)
z�
        L{HTTPChannel.writeHeaders} removes linear whitespace from the
        list of header names and values it receives.
        r�rvsOK)ry�code�reasonr��: r�r�r3N)
r'rr r�r��writeHeadersrSr(rQr�)rF�	componentr�r��sanitizedHeaderLines     r4�*test_writeHeadersSanitizesLinearWhitespacezGHTTPChannelSanitizationTests.test_writeHeadersSanitizesLinearWhitespacews���
9�	�I�'�)�I��&�&�(�G��"�"�9�-�� � �#���#�Y�/�0�	
!�
��
�
�&�&����
�
 �
������!����*�+����	
�-	r3N)r.r/r0r1rr2r3r4rrrs���$r3rc��eZdZdZd�Zy)�HTTPClientSanitizationTestsz<
    Test that L{http.HTTPClient} sanitizes its output.
    c�,�tD]�}t�}tj�}|j	|�|j||�|j
|j�j�djttg�g���y)z�
        L{HTTPClient.sendHeader} replaces linear whitespace in its
        header keys and values with a single space.
        rN)r'rr �
HTTPClientr�r�rQr�r�rSr()rFrr�r�s    r4�(test_sendHeaderSanitizesLinearWhitespacezDHTTPClientSanitizationTests.test_sendHeaderSanitizesLinearWhitespace�sz��
9�	�I�'�)�I��_�_�&�F��!�!�)�,����i��3�������!�,�,�.����^�^�<�=�>�
�	r3N)r.r/r0r1rr2r3r4rr�s���
r3rc�,�eZdZdZdZd�Zd�Zd�Zd�Zy)�HexHelperTestszM
    Test the L{http._hexint} and L{http._ishexdigits} helper functions.
    )r3s0x1234sfedss-123+123c�\�dD]'}|jdtj|���)y)zr
        L{_ishexdigits()} returns L{True} for nonempy bytestrings containing
        hexadecimal digits.
        )r�sabcdefsAB1234sfeds	123467890TN)rkr �_ishexdigits�rFr�s  r4�
test_isHexzHexHelperTests.test_isHex�s-��
E�	6�A��M�M�$�� 1� 1�!� 4�5�	6r3c���|jdtjd��|jdtjd��|jdtjd��y)zK
        L{_hexint()} returns the integer equivalent of the input.
        r�r��r�i#Ѽ
sabCD123N)rQr �_hexintrEs r4�test_decodeszHexHelperTests.test_decodes�sO��	
����T�\�\�$�/�0�����t�|�|�E�2�3�����D�L�L��$<�=r3c�p�|jD]'}|jdtj|���)y)z�
        L{_ishexdigits()} returns L{False} for bytestrings that don't contain
        hexadecimal digits, including the empty string.
        FN)�
badStringsrkr r r!s  r4�
test_isNotHexzHexHelperTests.test_isNotHex�s0��
���	7�A��M�M�%��!2�!2�1�!5�6�	7r3c�p�|jD]'}|jttj|��)y)zb
        L{_hexint()} raises L{ValueError} for bytestrings that can't
        be decoded.
        N)r(rYrZr r%r!s  r4�test_decodeNotHexz HexHelperTests.test_decodeNotHex�s-��
���	;�A����j�$�,�,��:�	;r3N)	r.r/r0r1r(r"r&r)r+r2r3r4rr�s"���<�J�6�>�7�;r3r)pr1r�rbrM�ior�	itertoolsr�typingrrrr�urllib.parser	r
r�zope.interfacerr
r�zope.interface.verifyrrE�twisted.internetr�twisted.internet.errorrr�twisted.internet.taskr�twisted.internet.testingrrr�twisted.loggerr�twisted.protocolsr�twisted.python.compatrr�twisted.python.componentsr�twisted.python.failurer�twisted.test.test_internetr�
twisted.trial�twisted.trial.unittestr�twisted.webr r!r"�twisted.web.httpr#r$r%�twisted.web.test.requesthelperr&r'r(r)�_utilr+rvr-r=r+r?r	rJrir��INonQueuedRequestFactoryr��DummyNewHTTPHandlerProxyr�r�rr�r�r�r�r�rrr
r#r-r;rsr�r�r�r�rPr�rZrqrtr�r�r�r�r�r��SynchronousTestCaserrrr2r3r4�<module>rEsM���
��
���"��$�-�A�A�.��$�A�'���
.�&�:�7�*�4�"�+�0�0�S�S���/����6�6����.;�t�|�|�;�!9�9Q� R��
�H�%�%�
�<�t�|�|��"1�1A�B��
�$�
'�
'�(�1�*�1�)�1�4�4G�H��	'�)�	'�3�3E�F��,����,��,!7�!7�HcA�8�$�$�&7�cA�L0�<�0�f�,��.	:�<�	:�p5�(�+�+�->�p5�f%�H�%�%�%�D))�H�%�%�))�XZD�h�/�/�ZD�z3��)�)�3�l�/
�x�(�(�/
�dD8�H�D8�NQ
�8�#4�#4�Q
�h
uE�H�%�%�'8�uE�pI
�8�$�$�I
�XRO�(�+�+�RO�j�4�?�?��)�x�0�0�)�.U:�8�$�$�&7�U:�p k'�H�-�-�k'�\N
�8�#4�#4�6G�N
�b#�"4
�x�'8�'8�4
�nz1�X�.�.�z1�z	)�8�#?�#?�)�X�(�">�">��*%;�X�1�1�%;r3

Zerion Mini Shell 1.0