§
    ÉtºfLN  ã                   ó&  — d Z ddlmZmZ ddlmZ ddlmZmZm	Z	m
Z
mZ ddlmZ ddlmZ ddlmZ  G d„ d	e¦  «        Z G d
„ d¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ d¦  «        Z G d„ de¦  «        ZdS )z 
Test for L{twisted.web.proxy}.
é    )ÚMemoryReactorÚ StringTransportWithDisconnection)ÚTestCase)ÚProxyClientÚProxyClientFactoryÚProxyRequestÚReverseProxyRequestÚReverseProxyResource)ÚResource)ÚSite©ÚDummyRequestc                   ó6   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	dS )	ÚReverseProxyResourceTestsz,
    Tests for L{ReverseProxyResource}.
    c                 ó¬  — t          ¦   «         }t          ¦   «         }t          ddd|¦  «        }|                     d|¦  «         t	          |¦  «        }t          ¦   «         }|                     d¦  «        }|                     |¦  «         |                      |j	        d¦  «         | 
                    d|z   dz   ¦  «         |j        \  \  }	}
}}}|                      |	d¦  «         |                      |
d¦  «         |                      |t          ¦  «         |                      |j        |¦  «         |                      |j        d         d	¦  «         dS )
z›
        Check that a request pointing at C{uri} produce a new proxy connection,
        with the path of this request pointing at C{expectedURI}.
        ú	127.0.0.1éÒ  ó   /paths   indexNs   GET s     HTTP/1.1
Accept: text/html

ó   hosts   127.0.0.1:1234)r   r   r
   ÚputChildr   r   ÚbuildProtocolÚmakeConnectionÚ
addCleanupÚconnectionLostÚdataReceivedÚ
tcpClientsÚassertEqualÚassertIsInstancer   ÚrestÚheaders)ÚselfÚuriÚexpectedURIÚrootÚreactorÚresourceÚsiteÚ	transportÚchannelÚhostÚportÚfactoryÚ_timeoutÚ
_bind_addrs                 úZ/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/web/test/test_proxy.pyÚ_testRenderz%ReverseProxyResourceTests._testRender   sF  € õ
 ‰zŒzˆÝ‘/”/ˆÝ'¨°T¸8ÀWÑMÔMˆØ�Š�h Ñ)Ô)Ð)Ý�D‰zŒzˆå4Ñ6Ô6ˆ	Ø×$Ò$ TÑ*Ô*ˆØ×Ò˜yÑ)Ô)Ð)à�Š˜Ô.°Ñ5Ô5Ð5à×Ò˜W s™]Ð-VÑVÑWÔWÐWà8?Ô8JÑ5Ñ	4ˆ$��g˜x¨à×Ò˜˜{Ñ+Ô+Ð+Ø×Ò˜˜tÑ$Ô$Ð$ð 	×Ò˜gÕ'9Ñ:Ô:Ð:Ø×Ò˜œ {Ñ3Ô3Ð3Ø×Ò˜œ¨Ô1Ð3DÑEÔEÐEÐEÐEó    c                 ó.   — |                       dd¦  «        S )z˜
        Test that L{ReverseProxyResource.render} initiates a connection to the
        given server with a L{ProxyClientFactory} as parameter.
        s   /indexr   ©r0   ©r!   s    r/   Útest_renderz%ReverseProxyResourceTests.test_render8   s   € ð
 ×Ò 	¨8Ñ4Ô4Ð4r1   c                 ó.   — |                       dd¦  «        S )zÆ
        Test that L{ReverseProxyResource.render} will instantiate a child
        resource that will initiate a connection to the given server
        requesting the apropiate url subpath.
        s   /index/page1s   /path/page1r3   r4   s    r/   Útest_render_subpagez-ReverseProxyResourceTests.test_render_subpage?   s   € ð ×Ò °Ñ@Ô@Ð@r1   c                 ó.   — |                       dd¦  «        S )zr
        Test that L{ReverseProxyResource.render} passes query parameters to the
        created factory.
        s   /index?foo=bars   /path?foo=barr3   r4   s    r/   Útest_renderWithQueryz.ReverseProxyResourceTests.test_renderWithQueryG   s   € ð
 ×ÒÐ 1Ð3CÑDÔDÐDr1   c                 óŠ  — t          ¦   «         }t          ddd|¦  «        }|                     dd¦  «        }|                      |t          ¦  «         |                      |j        d¦  «         |                      |j        d¦  «         |                      |j        d¦  «         |                      |j	        |j	        ¦  «         dS )a  
        The L{ReverseProxyResource.getChild} method should return a resource
        instance with the same class as the originating resource, forward
        port, host, and reactor values, and update the path value with the
        value passed.
        r   r   r   ó   fooNs	   /path/foo)
r   r
   ÚgetChildr   r   Úpathr+   r*   ÚassertIdenticalr%   )r!   r%   r&   Úchilds       r/   Útest_getChildz'ReverseProxyResourceTests.test_getChildN   sµ   € õ  ‘/”/ˆÝ'¨°T¸8ÀWÑMÔMˆØ×!Ò! &¨$Ñ/Ô/ˆà×Ò˜eÕ%9Ñ:Ô:Ð:Ø×Ò˜œ \Ñ2Ô2Ð2Ø×Ò˜œ TÑ*Ô*Ð*Ø×Ò˜œ [Ñ1Ô1Ð1Ø×Ò˜Uœ]¨HÔ,<Ñ=Ô=Ð=Ð=Ð=r1   c                 óŠ   — t          ddd¦  «        }|                     dd¦  «        }|                      |j        d¦  «         dS )zu
        The L{ReverseProxyResource} return by C{getChild} has a path which has
        already been quoted.
        r   r   r   s    /%Ns   /path/%20%2F%25)r
   r<   r   r=   )r!   r&   r?   s      r/   Útest_getChildWithSpecialz2ReverseProxyResourceTests.test_getChildWithSpecial_   sI   € õ
 (¨°T¸8ÑDÔDˆØ×!Ò! &¨$Ñ/Ô/ˆØ×Ò˜œÐ%7Ñ8Ô8Ð8Ð8Ð8r1   N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r0   r5   r7   r9   r@   rB   © r1   r/   r   r      s�   € € € € € ðð ðFð Fð Fð:5ð 5ð 5ðAð Að AðEð Eð Eð>ð >ð >ð"9ð 9ð 9ð 9ð 9r1   r   c                   ó*   — e Zd ZdZd„ Zd„ Zd„ Zd„ ZdS )ÚDummyChannelzÙ
    A dummy HTTP channel, that does nothing but holds a transport and saves
    connection lost.

    @ivar transport: the transport used by the client.
    @ivar lostReason: the reason saved at connection lost.
    c                 ó"   — || _         d| _        dS )z4
        Hold a reference to the transport.
        N)r(   Ú
lostReason)r!   r(   s     r/   Ú__init__zDummyChannel.__init__r   s   € ð #ˆŒØˆŒˆˆr1   c                 ó   — || _         dS )z;
        Keep track of the connection lost reason.
        N)rK   )r!   Úreasons     r/   r   zDummyChannel.connectionLosty   s   € ð !ˆŒˆˆr1   c                 ó4   — | j                              ¦   «         S )z:
        Get peer information from the transport.
        )r(   ÚgetPeerr4   s    r/   rP   zDummyChannel.getPeer   ó   € ð Œ~×%Ò%Ñ'Ô'Ð'r1   c                 ó4   — | j                              ¦   «         S )z:
        Get host information from the transport.
        )r(   ÚgetHostr4   s    r/   rS   zDummyChannel.getHost…   rQ   r1   N)rC   rD   rE   rF   rL   r   rP   rS   rG   r1   r/   rI   rI   i   sZ   € € € € € ðð ðð ð ð!ð !ð !ð(ð (ð (ð(ð (ð (ð (ð (r1   rI   c                   ó|   — e Zd ZdZd„ Zd„ Zdd„Zd„ Zd	„ Zd
„ Z	d„ Z
	 	 	 dd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )ÚProxyClientTestsz#
    Tests for L{ProxyClient}.
    c                 ó¾   — |                      d¦  «        \  }}|                      d¦  «        }|                     d¦  «        }|t          d„ |D ¦   «         ¦  «        |fS )aC  
        Parse the headers out of some web content.

        @param content: Bytes received from a web server.
        @return: A tuple of (requestLine, headers, body). C{headers} is a dict
            of headers, C{requestLine} is the first line (e.g. "POST /foo ...")
            and C{body} is whatever is left.
        s   

ó   
r   c              3   ó@   K  — | ]}|                      d ¦  «        V — ŒdS )ó   : N)Úsplit)Ú.0Úheaders     r/   ú	<genexpr>z4ProxyClientTests._parseOutHeaders.<locals>.<genexpr>�   s.   è è € Ð!LÐ!L¸& &§,¢,¨uÑ"5Ô"5Ð!LÐ!LÐ!LÐ!LÐ!LÐ!Lr1   )rZ   ÚpopÚdict)r!   Úcontentr    ÚbodyÚrequestLines        r/   Ú_parseOutHeadersz!ProxyClientTests._parseOutHeaders‘   s]   € ð  Ÿš kÑ2Ô2‰ˆ�Ø—-’- Ñ(Ô(ˆØ—k’k !‘n”nˆØ�TÐ!LÐ!LÀGÐ!LÑ!LÔ!LÑLÔLÈdÐSÐSr1   c                 ó    — t          |¦  «        S )z�
        Make a dummy request object for the URL path.

        @param path: A URL path, beginning with a slash.
        @return: A L{DummyRequest}.
        r   )r!   r=   s     r/   ÚmakeRequestzProxyClientTests.makeRequestŸ   s   € õ ˜DÑ!Ô!Ð!r1   ó   GETNr1   c                 óJ   — |€ddi}d|j         z   }t          ||d|||¦  «        S )a´  
        Make a L{ProxyClient} object used for testing.

        @param request: The request to use.
        @param method: The HTTP method to use, GET by default.
        @param headers: The HTTP headers to use expressed as a dict. If not
            provided, defaults to {'accept': 'text/html'}.
        @param requestBody: The body of the request. Defaults to the empty
            string.
        @return: A L{ProxyClient}
        Nó   acceptó	   text/htmló   /ó   HTTP/1.0)Úpostpathr   )r!   ÚrequestÚmethodr    ÚrequestBodyr=   s         r/   ÚmakeProxyClientz ProxyClientTests.makeProxyClient¨   s8   € ð ˆ?Ø  ,Ð/ˆGØ�gÔ&Ñ&ˆÝ˜6 4¨°g¸{ÈGÑTÔTÐTr1   c                 óZ   — t          ¦   «         }||_        |                     |¦  «         |S )z»
        Connect a proxy client to a L{StringTransportWithDisconnection}.

        @param proxyClient: A L{ProxyClient}.
        @return: The L{StringTransportWithDisconnection}.
        )r   Úprotocolr   )r!   ÚproxyClientÚclientTransports      r/   ÚconnectProxyzProxyClientTests.connectProxy¹   s1   € õ ;Ñ<Ô<ˆØ#.ˆÔ Ø×"Ò" ?Ñ3Ô3Ð3ØÐr1   c                 óì   — |                       |¦  «         |j                             ¦   «         }|                      |¦  «        \  }}}|                      ||¦  «         |                      ||¦  «         |S )a`  
        Assert that C{proxyClient} sends C{headers} when it connects.

        @param proxyClient: A L{ProxyClient}.
        @param requestLine: The request line we expect to be sent.
        @param headers: A dict of headers we expect to be sent.
        @return: If the assertion is successful, return the request body as
            bytes.
        )ru   r(   Úvaluerc   r   )r!   rs   rb   r    ÚrequestContentÚreceivedLineÚreceivedHeadersra   s           r/   ÚassertForwardsHeadersz&ProxyClientTests.assertForwardsHeadersÅ   sw   € ð 	×Ò˜+Ñ&Ô&Ð&Ø$Ô.×4Ò4Ñ6Ô6ˆØ.2×.CÒ.CÀNÑ.SÔ.SÑ+ˆ�o tØ×Ò˜ {Ñ3Ô3Ð3Ø×Ò˜¨'Ñ2Ô2Ð2Øˆr1   c                 ó  — dt          |¦  «                             d¦  «        z   dz   |z   g}|D ]%\  }}|D ]}|                     |dz   |z   ¦  «         ŒŒ&|                     d|g¦  «         d                     |¦  «        S )Ns	   HTTP/1.0 Úasciió    rY   r1   rW   )ÚstrÚencodeÚappendÚextendÚjoin)	r!   ÚcodeÚmessager    ra   Úlinesr\   Úvaluesrw   s	            r/   ÚmakeResponseBytesz"ProxyClientTests.makeResponseBytesÖ   sš   € Ø¥ D¡	¤	× 0Ò 0°Ñ 9Ô 9Ñ9¸DÑ@À7ÑJÐKˆØ%ð 	5ð 	5‰NˆF�FØð 5ð 5�Ø—’˜V e™^¨eÑ3Ñ4Ô4Ð4Ð4ð5à�Š�c˜4�[Ñ!Ô!Ð!Ø�|Š|˜EÑ"Ô"Ð"r1   c                 óª  — |                       |j        |¦  «         |                       |j        |¦  «         t          |j                             ¦   «         ¦  «        }|                     ¦   «          |dd…         }|                     ¦   «          |                       ||¦  «         |                       d                     |j        ¦  «        |¦  «         dS )aK  
        Assert that C{request} has forwarded a response from the server.

        @param request: A L{DummyRequest}.
        @param code: The expected HTTP response code.
        @param message: The expected HTTP message.
        @param headers: The expected HTTP headers.
        @param body: The expected response body.
        Nr1   )	r   ÚresponseCodeÚresponseMessageÚlistÚresponseHeadersÚgetAllRawHeadersÚsortrƒ   Úwritten)r!   rm   r„   r…   r    ra   rz   ÚexpectedHeaderss           r/   ÚassertForwardsResponsez'ProxyClientTests.assertForwardsResponseÞ   sÃ   € ð 	×Ò˜Ô-¨tÑ4Ô4Ð4Ø×Ò˜Ô0°'Ñ:Ô:Ð:Ý˜wÔ6×GÒGÑIÔIÑJÔJˆØ×ÒÑÔÐØ! ! ! !œ*ˆØ×ÒÑÔÐØ×Ò˜¨/Ñ:Ô:Ð:Ø×Ò˜Ÿš '¤/Ñ2Ô2°DÑ9Ô9Ð9Ð9Ð9r1   Tc                 óü  — |                       d¦  «        }|                      ||ddi|¦  «        }	|                      |	|dz   dddœ¦  «        }
|                      |
|¦  «         |	                     |                      ||||¦  «        ¦  «         |                      |||||¦  «         |r|	j                             ¦   «          |  	                    |	j        j
        ¦  «         |                      |j        d¦  «         dS )	z‹
        Build a fake proxy connection, and send C{data} over it, checking that
        it's forwarded to the originating request.
        r;   rh   ri   s    /foo HTTP/1.0ó   close)ó
   connectionrh   é   N)re   rp   r{   r   r   rˆ   r’   r(   ÚloseConnectionÚassertFalseÚ	connectedÚfinished)r!   r„   r…   r    ra   rn   ro   r—   rm   ÚclientÚreceivedBodys              r/   Ú_testDataForwardz!ProxyClientTests._testDataForwardñ   s"  € ð ×"Ò" 6Ñ*Ô*ˆØ×%Ò%Ø�V˜i¨Ð6¸ñ
ô 
ˆð ×1Ò1ØØÐ&Ñ&Ø$°Ð>Ð>ñ
ô 
ˆð 	×Ò˜ {Ñ3Ô3Ð3ð 	×Ò˜D×2Ò2°4¸À'È4ÑPÔPÑQÔQÐQð 	×#Ò# G¨T°7¸GÀTÑJÔJÐJð ð 	.ØÔ×+Ò+Ñ-Ô-Ð-ð
 	×Ò˜Ô)Ô3Ñ4Ô4Ð4Ø×Ò˜Ô)¨1Ñ-Ô-Ð-Ð-Ð-r1   c                 ó<   — |                       dddddgfgd¦  «        S )zÃ
        When connected to the server, L{ProxyClient} should send the saved
        request, with modifications of the headers, and then forward the result
        to the parent request.
        éÈ   ó   OKó   Fooó   bars   bazó   Some data
©r�   r4   s    r/   Útest_forwardzProxyClientTests.test_forward  s3   € ð ×$Ò$Ø�˜& 6¨6Ð"2Ð3Ð4Ð6Fñ
ô 
ð 	
r1   c                 ó>   — |                       ddddgfgddd¦  «        S )z~
        Try to post content in the request, and check that the proxy client
        forward the body of the request.
        rŸ   r    r¡   r¢   r£   ó   POSTó   Some contentr¤   r4   s    r/   Útest_postDatazProxyClientTests.test_postData'  s4   € ð
 ×$Ò$Ø�˜& 6 (Ð+Ð,Ð.>ÀÈñ
ô 
ð 	
r1   c                 ó2   — |                       ddg d¦  «        S )z’
        If the response contains a status with a message, it should be
        forwarded to the parent request with all the information.
        i”  s	   Not Foundr1   r¤   r4   s    r/   Útest_statusWithMessagez'ProxyClientTests.test_statusWithMessage0  s   € ð
 ×$Ò$ S¨,¸¸CÑ@Ô@Ð@r1   c           
      ó˜   — d}|                       dddt          t          |¦  «        ¦  «                             d¦  «        gfg|¦  «        S )z�
        If the response contains a I{Content-Length} header, the inbound
        request object should still only have C{finish} called on it once.
        ó   foo bar bazrŸ   r    ó   Content-Lengthr}   ©r�   r   Úlenr€   ©r!   Údatas     r/   Útest_contentLengthz#ProxyClientTests.test_contentLength7  sQ   € ð
 ˆØ×$Ò$Ø�Ð+­cµ#°d±)´)©n¬n×.CÒ.CÀGÑ.LÔ.LÐ-MÐNÐOÐQUñ
ô 
ð 	
r1   c           
      óœ   — d}|                       dddt          t          |¦  «        ¦  «                             d¦  «        gfg|d¬¦  «        S )zŸ
        If the response contains a I{Content-Length} header, the outgoing
        connection is closed when all response body data has been received.
        r­   rŸ   r    r®   r}   F)r—   r¯   r±   s     r/   Útest_losesConnectionz%ProxyClientTests.test_losesConnectionA  sZ   € ð
 ˆØ×$Ò$ØØØ¥#¥c¨$¡i¤i¡.¤.×"7Ò"7¸Ñ"@Ô"@Ð!AÐBÐCØØ ð %ñ 
ô 
ð 	
r1   c                 óp   — t          ddddddœdd¦  «        }|                      |j        dd	d
œ¦  «         dS )z®
        The headers given at initialization should be modified:
        B{proxy-connection} should be removed if present, and B{connection}
        should be added.
        rf   ó   /foork   ri   r;   )rh   s   proxy-connectionr1   Nr”   ©rh   r•   )r   r   r    )r!   r›   s     r/   Útest_headersCleanupsz%ProxyClientTests.test_headersCleanupsO  s`   € õ ØØØØ$¸6ÐBÐBØØñ
ô 
ˆð 	×ÒØŒN¨ÀXÐNÐNñ	
ô 	
ð 	
ð 	
ð 	
r1   c                 ó    — ddddœ}|                      ¦   «         }d|d<   |d= t          ddd	|d
d¦  «        }|                      |d|¦  «         dS )z¶
        The proxy doesn't really know what to do with keepalive things from
        the remote server, so we stomp over any keepalive header we get from
        the client.
        ri   s   300ó
   keep-alive)rh   r»   r•   r”   r•   rf   r·   rk   r1   Ns   GET /foo HTTP/1.0)Úcopyr   r{   )r!   r    r‘   r›   s       r/   Útest_keepaliveNotForwardedz+ProxyClientTests.test_keepaliveNotForwardeda  sp   € ð $Ø!Ø(ð
ð 
ˆð
 "Ÿ,š,™.œ.ˆØ)1ˆ˜Ñ&Ø˜MÐ*Ý˜V W¨k¸7ÀCÈÑNÔNˆØ×"Ò" 6Ð+?ÀÑQÔQÐQÐQÐQr1   c           	      ó0  — |                       d¦  «        }|j                             ddg¦  «         |j                             ddg¦  «         |j                             ddg¦  «         |                      |dd	i¬
¦  «        }|                      |¦  «         dgdgdgdœ}|                     |                      dd|                     ¦   «         d¦  «        ¦  «         |                      |ddt          |                     ¦   «         ¦  «        d¦  «         dS )zÞ
        L{server.Request} within the proxy sets certain response headers by
        default. When we get these headers back from the remote server, the
        defaults are overridden rather than simply appended.
        r;   s   servers   old-bars   dates   old-bazs   content-types   old/quxrh   ri   )r    r¢   s
   2010-01-01s   application/x-baz)s   Servers   Dateó   Content-TyperŸ   r    r1   N)
re   r�   ÚsetRawHeadersrp   ru   r   rˆ   Úitemsr’   rŒ   )r!   rm   r›   r    s       r/   Útest_defaultHeadersOverriddenz.ProxyClientTests.test_defaultHeadersOverriddenr  s  € ð ×"Ò" 6Ñ*Ô*ˆØÔ×-Ò-¨i¸*¸ÑFÔFÐFØÔ×-Ò-¨g¸
°|ÑDÔDÐDØÔ×-Ò-¨oÀ
¸|ÑLÔLÐLØ×%Ò% g¸	À<Ð7PÐ%ÑQÔQˆØ×Ò˜&Ñ!Ô!Ð!à�xØ#�_Ø2Ð3ð
ð 
ˆð
 	×Ò˜D×2Ò2°3¸¸w¿}º}¹¼ÐPSÑTÔTÑUÔUÐUØ×#Ò# G¨S°%½¸g¿mºm¹o¼oÑ9NÔ9NÐPSÑTÔTÐTÐTÐTr1   )rf   Nr1   )rf   r1   T)rC   rD   rE   rF   rc   re   rp   ru   r{   rˆ   r’   r�   r¥   r©   r«   r³   rµ   r¹   r½   rÂ   rG   r1   r/   rU   rU   Œ   s6  € € € € € ðð ðTð Tð Tð"ð "ð "ðUð Uð Uð Uð"
ð 
ð 
ðð ð ð"#ð #ð #ð:ð :ð :ð2 ØØð*.ð *.ð *.ð *.ðX
ð 
ð 
ð
ð 
ð 
ðAð Að Að
ð 
ð 
ð
ð 
ð 
ð
ð 
ð 
ð$Rð Rð Rð"Uð Uð Uð Uð Ur1   rU   c                   ó   — e Zd ZdZd„ Zd„ ZdS )ÚProxyClientFactoryTestsz*
    Tests for L{ProxyClientFactory}.
    c                 óø  — t          dg¦  «        }t          dddddid|¦  «        }|                     dd¦  «         |                      |j        d	¦  «         |                      |j        d
¦  «         |                      t          |j                             ¦   «         ¦  «        ddgfg¦  «         |                      d 	                    |j
        ¦  «        d¦  «         |                      |j        d¦  «         dS )zƒ
        Check that L{ProxyClientFactory.clientConnectionFailed} produces
        a B{501} response to the parent request.
        r;   rf   r·   rk   rh   ri   Ú Niõ  s   Gateway errorr¿   r1   s   <H1>Could not connect</H1>r–   )r   r   ÚclientConnectionFailedr   rŠ   r‹   rŒ   r�   rŽ   rƒ   r�   rš   )r!   rm   r,   s      r/   Útest_connectionFailedz-ProxyClientFactoryTests.test_connectionFailedŒ  s  € õ
  ˜xÑ(Ô(ˆÝ$Ø�G˜[¨9°lÐ*CÀRÈñ
ô 
ˆð 	×&Ò& t¨TÑ2Ô2Ð2Ø×Ò˜Ô-¨sÑ3Ô3Ð3Ø×Ò˜Ô0Ð2BÑCÔCÐCØ×ÒÝ�Ô(×9Ò9Ñ;Ô;Ñ<Ô<Ø ˜~Ð.Ð/ñ	
ô 	
ð 	
ð 	×Ò˜Ÿš '¤/Ñ2Ô2Ð4QÑRÔRÐRØ×Ò˜Ô)¨1Ñ-Ô-Ð-Ð-Ð-r1   c                 óp  — t          dddddidd¦  «        }|                     d¦  «        }|                      |t          ¦  «         |                      |j        d¦  «         |                      |j        d¦  «         |                      |j        d¦  «         |                      |j        ddd	œ¦  «         dS )
zŸ
        L{ProxyClientFactory.buildProtocol} should produce a L{ProxyClient}
        with the same values of attributes (with updates on the headers).
        rf   r·   rk   rh   ri   s	   Some dataNr”   r¸   )	r   r   r   r   r   Úcommandr   r²   r    )r!   r,   Úprotos      r/   Útest_buildProtocolz*ProxyClientFactoryTests.test_buildProtocol   sÊ   € õ
 %Ø�G˜[¨9°lÐ*CÀ\ÐSWñ
ô 
ˆð ×%Ò% dÑ+Ô+ˆØ×Ò˜e¥[Ñ1Ô1Ð1Ø×Ò˜œ¨Ñ/Ô/Ð/Ø×Ò˜œ WÑ-Ô-Ð-Ø×Ò˜œ \Ñ2Ô2Ð2Ø×ÒØŒM |ÀHÐMÐMñ	
ô 	
ð 	
ð 	
ð 	
r1   N)rC   rD   rE   rF   rÈ   rÌ   rG   r1   r/   rÄ   rÄ   ‡  s<   € € € € € ðð ð.ð .ð .ð(
ð 
ð 
ð 
ð 
r1   rÄ   c                   ó2   — e Zd ZdZd
d„Zd„ Zd„ Zd„ Zd„ Zd	S )ÚProxyRequestTestsz$
    Tests for L{ProxyRequest}.
    rf   r1   c                 ó°  — t          ¦   «         }t          |¦  «        }t          ¦   «         }t          |d|¦  «        }|                     t          |¦  «        ¦  «         |                     |¦  «         |                     |d|z   d¦  «         |                      t          |j	        ¦  «        d¦  «         |                      |j	        d         d         d¦  «         |                      |j	        d         d         d¦  «         |j	        d         d         }	|  
                    |	t          ¦  «         |                      |	j        |¦  «         |                      |	j        d¦  «         |                      |	j        d	d
i¦  «         |                      |	j        |¦  «         |                      |	j        |¦  «         |                      |	j        |¦  «         dS )z…
        Build a request pointing at C{uri}, and check that a proxied request
        is created, pointing a C{expectedURI}.
        Fs   http://example.comrk   r–   r   úexample.coméP   é   r   ó   example.comN)r   rI   r   r   Ú	gotLengthr°   ÚhandleContentChunkÚrequestReceivedr   r   r   r   rÊ   Úversionr    r²   r   Úfather)
r!   r"   r#   rn   r²   r(   r)   r%   rm   r,   s
             r/   Ú_testProcesszProxyRequestTests._testProcess·  s­  € õ
 5Ñ6Ô6ˆ	Ý˜yÑ)Ô)ˆÝ‘/”/ˆÝ˜w¨¨wÑ7Ô7ˆØ×Ò�#˜d™)œ)Ñ$Ô$Ð$Ø×"Ò" 4Ñ(Ô(Ð(Ø×Ò Ð(=ÀÑ(CÀ[ÑQÔQÐQà×Ò�˜WÔ/Ñ0Ô0°!Ñ4Ô4Ð4Ø×Ò˜Ô+¨AÔ.¨qÔ1°=ÑAÔAÐAØ×Ò˜Ô+¨AÔ.¨qÔ1°2Ñ6Ô6Ð6àÔ$ QÔ'¨Ô*ˆØ×Ò˜gÕ'9Ñ:Ô:Ð:Ø×Ò˜œ¨&Ñ1Ô1Ð1Ø×Ò˜œ¨+Ñ6Ô6Ð6Ø×Ò˜œ¨7°NÐ*CÑDÔDÐDØ×Ò˜œ tÑ,Ô,Ð,Ø×Ò˜œ {Ñ3Ô3Ð3Ø×Ò˜œ¨Ñ1Ô1Ð1Ð1Ð1r1   c                 ó.   — |                       dd¦  «        S )a�  
        L{ProxyRequest.process} should create a connection to the given server,
        with a L{ProxyClientFactory} as connection factory, with the correct
        parameters:
            - forward comment, version and data values
            - update headers with the B{host} value
            - remove the host from the URL
            - pass the request as parent request
        ó   /foo/bar©rÙ   r4   s    r/   Útest_processzProxyRequestTests.test_processÑ  s   € ð × Ò  ¨kÑ:Ô:Ð:r1   c                 ó.   — |                       dd¦  «        S )z£
        If the incoming request doesn't contain a slash,
        L{ProxyRequest.process} should add one when instantiating
        L{ProxyClientFactory}.
        r1   rj   rÜ   r4   s    r/   Ú test_processWithoutTrailingSlashz2ProxyRequestTests.test_processWithoutTrailingSlashÝ  s   € ð × Ò   dÑ+Ô+Ð+r1   c                 ó2   — |                       dddd¦  «        S )zl
        L{ProxyRequest.process} should be able to retrieve request body and
        to forward it.
        rÛ   r§   r¨   rÜ   r4   s    r/   Útest_processWithDataz&ProxyRequestTests.test_processWithDataå  s   € ð
 × Ò  ¨k¸7ÀOÑTÔTÐTr1   c                 óÂ  — t          ¦   «         }t          |¦  «        }t          ¦   «         }t          |d|¦  «        }|                     d¦  «         |                     ddd¦  «         |                      t          |j        ¦  «        d¦  «         |                      |j        d         d         d¦  «         |                      |j        d         d         d¦  «         d	S )
z˜
        Check that L{ProxyRequest.process} correctly parse port in the incoming
        URL, and create an outgoing connection with this port.
        Fr   rf   s   http://example.com:1234/foo/barrk   r–   rÐ   r   N)	r   rI   r   r   rÔ   rÖ   r   r°   r   )r!   r(   r)   r%   rm   s        r/   Útest_processWithPortz&ProxyRequestTests.test_processWithPortì  sÒ   € õ
 5Ñ6Ô6ˆ	Ý˜yÑ)Ô)ˆÝ‘/”/ˆÝ˜w¨¨wÑ7Ô7ˆØ×Ò˜!ÑÔÐØ×Ò Ð(JÈKÑXÔXÐXð 	×Ò�˜WÔ/Ñ0Ô0°!Ñ4Ô4Ð4Ø×Ò˜Ô+¨AÔ.¨qÔ1°=ÑAÔAÐAØ×Ò˜Ô+¨AÔ.¨qÔ1°4Ñ8Ô8Ð8Ð8Ð8r1   N)rf   r1   )	rC   rD   rE   rF   rÙ   rÝ   rß   rá   rã   rG   r1   r/   rÎ   rÎ   ²  sq   € € € € € ðð ð2ð 2ð 2ð 2ð4
;ð 
;ð 
;ð,ð ,ð ,ðUð Uð Uð9ð 9ð 9ð 9ð 9r1   rÎ   c                   ó   — e Zd ZdZd„ ZdS )ÚDummyFactoryz>
    A simple holder for C{host} and C{port} information.
    c                 ó"   — || _         || _        d S )N)r*   r+   )r!   r*   r+   s      r/   rL   zDummyFactory.__init__  s   € ØˆŒ	ØˆŒ	ˆ	ˆ	r1   N)rC   rD   rE   rF   rL   rG   r1   r/   rå   rå   þ  s-   € € € € € ðð ðð ð ð ð r1   rå   c                   ó   — e Zd ZdZd„ ZdS )ÚReverseProxyRequestTestsz+
    Tests for L{ReverseProxyRequest}.
    c                 ó‚  — t          ¦   «         }t          |¦  «        }t          ¦   «         }t          |d|¦  «        }t	          dd¦  «        |_        |                     d¦  «         |                     ddd¦  «         |                      t          |j
        ¦  «        d¦  «         |                      |j
        d         d         d¦  «         |                      |j
        d         d         d¦  «         |j
        d         d	         }|                      |t          ¦  «         |                      |j        d
di¦  «         dS )a  
        L{ReverseProxyRequest.process} should create a connection to its
        factory host/port, using a L{ProxyClientFactory} instantiated with the
        correct parameters, and particularly set the B{host} header to the
        factory host.
        FrÐ   r   r   rf   rÛ   rk   r–   rÒ   r   rÓ   N)r   rI   r   r	   rå   r,   rÔ   rÖ   r   r°   r   r   r   r    )r!   r(   r)   r%   rm   r,   s         r/   rÝ   z%ReverseProxyRequestTests.test_process  s*  € õ 5Ñ6Ô6ˆ	Ý˜yÑ)Ô)ˆÝ‘/”/ˆÝ% g¨u°gÑ>Ô>ˆÝ& }°dÑ;Ô;ˆŒØ×Ò˜!ÑÔÐØ×Ò ¨°[ÑAÔAÐAð 	×Ò�˜WÔ/Ñ0Ô0°!Ñ4Ô4Ð4Ø×Ò˜Ô+¨AÔ.¨qÔ1°=ÑAÔAÐAØ×Ò˜Ô+¨AÔ.¨qÔ1°4Ñ8Ô8Ð8ð Ô$ QÔ'¨Ô*ˆØ×Ò˜gÕ'9Ñ:Ô:Ð:Ø×Ò˜œ¨7°NÐ*CÑDÔDÐDÐDÐDr1   N)rC   rD   rE   rF   rÝ   rG   r1   r/   rè   rè     s2   € € € € € ðð ðEð Eð Eð Eð Er1   rè   N)rF   Útwisted.internet.testingr   r   Útwisted.trial.unittestr   Útwisted.web.proxyr   r   r   r	   r
   Útwisted.web.resourcer   Útwisted.web.serverr   Útwisted.web.test.test_webr   r   rI   rU   rÄ   rÎ   rå   rè   rG   r1   r/   ú<module>rð      s  ððð ð UÐ TÐ TÐ TÐ TÐ TÐ TÐ TØ +Ð +Ð +Ð +Ð +Ð +ðð ð ð ð ð ð ð ð ð ð ð ð ð ð *Ð )Ð )Ð )Ð )Ð )Ø #Ð #Ð #Ð #Ð #Ð #Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2ðP9ð P9ð P9ð P9ð P9 ñ P9ô P9ð P9ðf (ð  (ð  (ð  (ð  (ñ  (ô  (ð  (ðFxUð xUð xUð xUð xU�xñ xUô xUð xUðv(
ð (
ð (
ð (
ð (
˜hñ (
ô (
ð (
ðVI9ð I9ð I9ð I9ð I9˜ñ I9ô I9ð I9ðXð ð ð ð ñ ô ð ðEð Eð Eð Eð E˜xñ Eô Eð Eð Eð Er1   