Ë
    ojLN  ã                   óú   — 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y)z 
Test for L{twisted.web.proxy}.
é    )ÚMemoryReactorÚ StringTransportWithDisconnection)ÚTestCase)ÚProxyClientÚProxyClientFactoryÚProxyRequestÚReverseProxyRequestÚReverseProxyResource)ÚResource)ÚSite©ÚDummyRequestc                   ó4   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z	y)	ÚReverseProxyResourceTestsz,
    Tests for L{ReverseProxyResource}.
    c                 óR  — t        «       }t        «       }t        ddd|«      }|j                  d|«       t	        |«      }t        «       }|j                  d«      }|j                  |«       | j                  |j                  d«       |j                  d|z   dz   «       |j                  \  \  }	}
}}}| j                  |	d«       | j                  |
d«       | j                  |t        «       | j                  |j                  |«       | j                  |j                   d   d	«       y)
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                 ú=/usr/lib/python3/dist-packages/twisted/web/test/test_proxy.pyÚ_testRenderz%ReverseProxyResourceTests._testRender   s  € ô
 ‹zˆÜ“/ˆÜ'¨°T¸8ÀWÓMˆØ�‰�h Ô)Ü�D‹zˆä4Ó6ˆ	Ø×$Ñ$ TÓ*ˆØ×Ñ˜yÔ)à�‰˜×.Ñ.°Ô5à×Ñ˜W s™]Ð-VÑVÔWà8?×8JÑ8JÑ5Ñ	4ˆ$��g˜x¨à×Ñ˜˜{Ô+Ø×Ñ˜˜tÔ$ð 	×Ñ˜gÔ'9Ô:Ø×Ñ˜Ÿ™ {Ô3Ø×Ñ˜Ÿ™¨Ñ1Ð3DÕEó    c                 ó&   — | j                  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Ð4r1   c                 ó&   — | j                  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                 ó&   — | j                  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ÐDr1   c                 óx  — t        «       }t        ddd|«      }|j                  dd«      }| j                  |t        «       | j	                  |j
                  d«       | j	                  |j                  d«       | j	                  |j                  d«       | j                  |j                  |j                  «       y)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ˆØ×!Ñ! &¨$Ó/ˆà×Ñ˜eÔ%9Ô:Ø×Ñ˜Ÿ™ \Ô2Ø×Ñ˜Ÿ™ TÔ*Ø×Ñ˜Ÿ™ [Ô1Ø×Ñ˜UŸ]™]¨H×,<Ñ,<Õ=r1   c                 óz   — t        ddd«      }|j                  dd«      }| j                  |j                  d«       y)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_   s9   € ô
 (¨°T¸8ÓDˆØ×!Ñ! &¨$Ó/ˆØ×Ñ˜Ÿ™Ð%7Õ8r1   N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r0   r5   r7   r9   r@   rB   © r1   r/   r   r      s(   „ ñòFò:5òAòEò>ó"9r1   r   c                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)Ú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| _        y)z4
        Hold a reference to the transport.
        N)r(   Ú
lostReason)r!   r(   s     r/   Ú__init__zDummyChannel.__init__r   s   € ð #ˆŒØˆ�r1   c                 ó   — || _         y)z;
        Keep track of the connection lost reason.
        N)rK   )r!   Úreasons     r/   r   zDummyChannel.connectionLosty   s   € ð !ˆ�r1   c                 ó6   — | j                   j                  «       S )z:
        Get peer information from the transport.
        )r(   ÚgetPeerr4   s    r/   rP   zDummyChannel.getPeer   ó   € ð �~‰~×%Ñ%Ó'Ð'r1   c                 ó6   — | j                   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   s   „ ñòò!ò(ó(r1   rI   c                   óz   — 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y)ÚProxyClientTestsz#
    Tests for L{ProxyClient}.
    c                 ó˜   — |j                  d«      \  }}|j                  d«      }|j                  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  — | ]  }|j                  d «      –— Œ y­w)ó   : N)Úsplit)Ú.0Úheaders     r/   ú	<genexpr>z4ProxyClientTests._parseOutHeaders.<locals>.<genexpr>�   s   è ø€ Ò!L¸& &§,¡,¨u×"5Ñ!Lùs   ‚)rZ   ÚpopÚdict)r!   Úcontentr    ÚbodyÚrequestLines        r/   Ú_parseOutHeadersz!ProxyClientTests._parseOutHeaders‘   sI   € ð  Ÿ™ kÓ2‰ˆ�Ø—-‘- Ó(ˆØ—k‘k !“nˆØœTÑ!LÀGÔ!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   Nc                 óL   — |€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}
        ó   acceptó	   text/htmló   /ó   HTTP/1.0)Úpostpathr   )r!   ÚrequestÚmethodr    ÚrequestBodyr=   s         r/   ÚmakeProxyClientz ProxyClientTests.makeProxyClient¨   s8   € ð ˆ?Ø  ,Ð/ˆGØ�g×&Ñ&Ñ&ˆÜ˜6 4¨°g¸{ÈGÓTÐTr1   c                 óJ   — t        «       }||_        |j                  |«       |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¹   s(   € ô ;Ó<ˆØ#.ˆÔ Ø×"Ñ" ?Ô3ØÐr1   c                 óÎ   — | j                  |«       |j                  j                  «       }| j                  |«      \  }}}| j	                  ||«       | 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.
        )rt   r(   Úvaluerc   r   )r!   rr   rb   r    ÚrequestContentÚreceivedLineÚreceivedHeadersra   s           r/   ÚassertForwardsHeadersz&ProxyClientTests.assertForwardsHeadersÅ   sb   € ð 	×Ñ˜+Ô&Ø$×.Ñ.×4Ñ4Ó6ˆØ.2×.CÑ.CÀNÓ.SÑ+ˆ�o tØ×Ñ˜ {Ô3Ø×Ñ˜¨'Ô2Øˆr1   c                 óâ   — dt        |«      j                  d«      z   dz   |z   g}|D ]#  \  }}|D ]  }|j                  |dz   |z   «       Œ Œ% |j                  d|g«       dj	                  |«      S )Ns	   HTTP/1.0 Úasciió    rY   r1   rW   )ÚstrÚencodeÚappendÚextendÚjoin)	r!   ÚcodeÚmessager    ra   Úlinesr\   Úvaluesrv   s	            r/   ÚmakeResponseBytesz"ProxyClientTests.makeResponseBytesÖ   s€   € Ø¤ D£	× 0Ñ 0°Ó 9Ñ9¸DÑ@À7ÑJÐKˆØ%ò 	5‰NˆF�FØò 5�Ø—‘˜V e™^¨eÑ3Õ4ñ5ð	5ð 	�‰�c˜4�[Ô!Ø�|‰|˜EÓ"Ð"r1   c                 ó~  — | j                  |j                  |«       | j                  |j                  |«       t        |j                  j                  «       «      }|j                  «        |dd }|j                  «        | j                  ||«       | j                  dj                  |j                  «      |«       y)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!   rl   rƒ   r„   r    ra   ry   ÚexpectedHeaderss           r/   ÚassertForwardsResponsez'ProxyClientTests.assertForwardsResponseÞ   s—   € ð 	×Ñ˜×-Ñ-¨tÔ4Ø×Ñ˜×0Ñ0°'Ô:Ü˜w×6Ñ6×GÑGÓIÓJˆØ×ÑÔØ!¡!˜*ˆØ×ÑÔØ×Ñ˜¨/Ô:Ø×Ñ˜Ÿ™ '§/¡/Ó2°DÕ9r1   c                 óÒ  — | j                  d«      }| j                  ||ddi|«      }	| j                  |	|dz   dddœ«      }
| j                  |
|«       |	j	                  | j                  ||||«      «       | j                  |||||«       |r|	j                  j                  «        | j                  |	j                  j                  «       | j                  |j                  d«       y)	z‹
        Build a fake proxy connection, and send C{data} over it, checking that
        it's forwarded to the originating request.
        r;   rg   rh   s    /foo HTTP/1.0ó   close)ó
   connectionrg   é   N)re   ro   rz   r   r   r‡   r‘   r(   ÚloseConnectionÚassertFalseÚ	connectedÚfinished)r!   rƒ   r„   r    ra   rm   rn   r–   rl   ÚclientÚreceivedBodys              r/   Ú_testDataForwardz!ProxyClientTests._testDataForwardñ   sì   € ð ×"Ñ" 6Ó*ˆØ×%Ñ%Ø�V˜i¨Ð6¸ó
ˆð ×1Ñ1ØØÐ&Ñ&Ø$°Ñ>ó
ˆð 	×Ñ˜ {Ô3ð 	×Ñ˜D×2Ñ2°4¸À'È4ÓPÔQð 	×#Ñ# G¨T°7¸GÀTÔJñ Ø×Ñ×+Ñ+Ô-ð
 	×Ñ˜×)Ñ)×3Ñ3Ô4Ø×Ñ˜×)Ñ)¨1Õ-r1   c                 ó4   — | j                  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  s.   € ð ×$Ñ$Ø�˜& 6¨6Ð"2Ð3Ð4Ð6Fó
ð 	
r1   c                 ó6   — | j                  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'  s/   € ð
 ×$Ñ$Ø�˜& 6 (Ð+Ð,Ð.>ÀÈó
ð 	
r1   c                 ó*   — | j                  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           
      óx   — d}| j                  dddt        t        |«      «      j                  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  sE   € ð
 ˆØ×$Ñ$Ø�Ð+¬c´#°d³)«n×.CÑ.CÀGÓ.LÐ-MÐNÐOÐQUó
ð 	
r1   c           
      ó|   — d}| j                  dddt        t        |«      «      j                  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  sN   € ð
 ˆØ×$Ñ$ØØØ¤#¤c¨$£i£.×"7Ñ"7¸Ó"@Ð!AÐBÐCØØ ð %ó 
ð 	
r1   c                 óh   — t        ddddddœdd«      }| j                  |j                  dd	d
œ«       y)z®
        The headers given at initialization should be modified:
        B{proxy-connection} should be removed if present, and B{connection}
        should be added.
        ó   GETó   /foorj   rh   r;   )rg   s   proxy-connectionr1   Nr“   ©rg   r”   )r   r   r    )r!   rš   s     r/   Útest_headersCleanupsz%ProxyClientTests.test_headersCleanupsO  sC   € ô ØØØØ$¸6ÑBØØó
ˆð 	×ÑØ�N‰N¨ÀXÑNõ	
r1   c                 ó†   — ddddœ}|j                  «       }d|d<   |d= t        ddd	|d
d«      }| j                  |d|«       y)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.
        rh   s   300ó
   keep-alive)rg   r»   r”   r“   r”   r¶   r·   rj   r1   Ns   GET /foo HTTP/1.0)Úcopyr   rz   )r!   r    r�   rš   s       r/   Útest_keepaliveNotForwardedz+ProxyClientTests.test_keepaliveNotForwardeda  sZ   € ð $Ø!Ø(ñ
ˆð
 "Ÿ,™,›.ˆØ)1ˆ˜Ñ&Ø˜MÐ*Ü˜V W¨k¸7ÀCÈÓNˆØ×"Ñ" 6Ð+?ÀÕQr1   c           	      óì  — | j                  d«      }|j                  j                  ddg«       |j                  j                  ddg«       |j                  j                  ddg«       | j                  |dd	i¬
«      }| j	                  |«       dgdgdgdœ}|j                  | j                  dd|j                  «       d«      «       | j                  |ddt        |j                  «       «      d«       y)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/quxrg   rh   )r    r¡   s
   2010-01-01s   application/x-baz)s   Servers   Dateó   Content-Typerž   rŸ   r1   N)
re   rŒ   ÚsetRawHeadersro   rt   r   r‡   Úitemsr‘   r‹   )r!   rl   rš   r    s       r/   Útest_defaultHeadersOverriddenz.ProxyClientTests.test_defaultHeadersOverriddenr  så   € ð ×"Ñ" 6Ó*ˆØ×Ñ×-Ñ-¨i¸*¸ÔFØ×Ñ×-Ñ-¨g¸
°|ÔDØ×Ñ×-Ñ-¨oÀ
¸|ÔLØ×%Ñ% g¸	À<Ð7PÐ%ÓQˆØ×Ñ˜&Ô!à�xØ#�_Ø2Ð3ñ
ˆð
 	×Ñ˜D×2Ñ2°3¸¸w¿}¹}»ÐPSÓTÔUØ×#Ñ# G¨S°%¼¸g¿m¹m»oÓ9NÐPSÕTr1   )r¶   Nr1   )r¶   r1   T)rC   rD   rE   rF   rc   re   ro   rt   rz   r‡   r‘   rœ   r¤   r¨   rª   r²   r´   r¹   r½   rÂ   rG   r1   r/   rU   rU   Œ   sh   „ ñòTò"óUò"
òò"#ò:ð2 ØØó*.òX
ò
òAò
ò
ò
ò$Ró"Ur1   rU   c                   ó   — e Zd ZdZd„ Zd„ Zy)ÚProxyClientFactoryTestsz*
    Tests for L{ProxyClientFactory}.
    c                 óÐ  — t        dg«      }t        dddddid|«      }|j                  dd«       | j                  |j                  d	«       | j                  |j
                  d
«       | j                  t        |j                  j                  «       «      ddgfg«       | j                  dj                  |j                  «      d«       | j                  |j                  d«       y)zƒ
        Check that L{ProxyClientFactory.clientConnectionFailed} produces
        a B{501} response to the parent request.
        r;   r¶   r·   rj   rg   rh   Ú Niõ  s   Gateway errorr¿   r1   s   <H1>Could not connect</H1>r•   )r   r   ÚclientConnectionFailedr   r‰   rŠ   r‹   rŒ   r�   r‚   r�   r™   )r!   rl   r,   s      r/   Útest_connectionFailedz-ProxyClientFactoryTests.test_connectionFailedŒ  sÓ   € ô
  ˜xÓ(ˆÜ$Ø�G˜[¨9°lÐ*CÀRÈó
ˆð 	×&Ñ& t¨TÔ2Ø×Ñ˜×-Ñ-¨sÔ3Ø×Ñ˜×0Ñ0Ð2BÔCØ×ÑÜ�×(Ñ(×9Ñ9Ó;Ó<Ø ˜~Ð.Ð/ô	
ð 	×Ñ˜Ÿ™ '§/¡/Ó2Ð4QÔRØ×Ñ˜×)Ñ)¨1Õ-r1   c                 ó\  — t        dddddidd«      }|j                  d«      }| j                  |t        «       | j	                  |j
                  d«       | j	                  |j                  d«       | j	                  |j                  d«       | j	                  |j                  ddd	œ«       y)
zŸ
        L{ProxyClientFactory.buildProtocol} should produce a L{ProxyClient}
        with the same values of attributes (with updates on the headers).
        r¶   r·   rj   rg   rh   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Ø×Ñ˜Ÿ™¨Ô/Ø×Ñ˜Ÿ™ WÔ-Ø×Ñ˜Ÿ™ \Ô2Ø×ÑØ�M‰M |ÀHÑMõ	
r1   N)rC   rD   rE   rF   rÈ   rÌ   rG   r1   r/   rÄ   rÄ   ‡  s   „ ñò.ó(
r1   rÄ   c                   ó0   — e Zd ZdZdd„Zd„ Zd„ Zd„ Zd„ Zy)	ÚProxyRequestTestsz$
    Tests for L{ProxyRequest}.
    c                 óT  — t        «       }t        |«      }t        «       }t        |d|«      }|j	                  t        |«      «       |j                  |«       |j                  |d|z   d«       | j                  t        |j                  «      d«       | j                  |j                  d   d   d«       | j                  |j                  d   d   d«       |j                  d   d   }	| j                  |	t        «       | j                  |	j                  |«       | j                  |	j                  d«       | j                  |	j                  d	d
i«       | j                  |	j                  |«       | j                  |	j                   |«       | j                  |	j"                  |«       y)z…
        Build a request pointing at C{uri}, and check that a proxied request
        is created, pointing a C{expectedURI}.
        Fs   http://example.comrj   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#   rm   r±   r(   r)   r%   rl   r,   s
             r/   Ú_testProcesszProxyRequestTests._testProcess·  sa  € ô
 5Ó6ˆ	Ü˜yÓ)ˆÜ“/ˆÜ˜w¨¨wÓ7ˆØ×Ñœ#˜d›)Ô$Ø×"Ñ" 4Ô(Ø×Ñ Ð(=ÀÑ(CÀ[ÔQà×Ñœ˜W×/Ñ/Ó0°!Ô4Ø×Ñ˜×+Ñ+¨AÑ.¨qÑ1°=ÔAØ×Ñ˜×+Ñ+¨AÑ.¨qÑ1°2Ô6à×$Ñ$ QÑ'¨Ñ*ˆØ×Ñ˜gÔ'9Ô:Ø×Ñ˜Ÿ™¨&Ô1Ø×Ñ˜Ÿ™¨+Ô6Ø×Ñ˜Ÿ™¨7°NÐ*CÔDØ×Ñ˜Ÿ™ tÔ,Ø×Ñ˜Ÿ™ {Ô3Ø×Ñ˜Ÿ™¨Õ1r1   c                 ó&   — | j                  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                 ó&   — | j                  dd«      S )z£
        If the incoming request doesn't contain a slash,
        L{ProxyRequest.process} should add one when instantiating
        L{ProxyClientFactory}.
        r1   ri   rÜ   r4   s    r/   Ú test_processWithoutTrailingSlashz2ProxyRequestTests.test_processWithoutTrailingSlashÝ  s   € ð × Ñ   dÓ+Ð+r1   c                 ó*   — | j                  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ÐTr1   c                 óv  — t        «       }t        |«      }t        «       }t        |d|«      }|j	                  d«       |j                  ddd«       | j                  t        |j                  «      d«       | j                  |j                  d   d   d«       | j                  |j                  d   d   d«       y	)
z˜
        Check that L{ProxyRequest.process} correctly parse port in the incoming
        URL, and create an outgoing connection with this port.
        Fr   r¶   s   http://example.com:1234/foo/barrj   r•   rÐ   r   N)	r   rI   r   r   rÔ   rÖ   r   r¯   r   )r!   r(   r)   r%   rl   s        r/   Útest_processWithPortz&ProxyRequestTests.test_processWithPortì  s©   € ô
 5Ó6ˆ	Ü˜yÓ)ˆÜ“/ˆÜ˜w¨¨wÓ7ˆØ×Ñ˜!ÔØ×Ñ Ð(JÈKÔXð 	×Ñœ˜W×/Ñ/Ó0°!Ô4Ø×Ñ˜×+Ñ+¨AÑ.¨qÑ1°=ÔAØ×Ñ˜×+Ñ+¨AÑ.¨qÑ1°4Õ8r1   N)r¶   r1   )	rC   rD   rE   rF   rÙ   rÝ   rß   rá   rã   rG   r1   r/   rÎ   rÎ   ²  s!   „ ñó2ò4
;ò,òUó9r1   rÎ   c                   ó   — e Zd ZdZd„ Zy)ÚDummyFactoryz>
    A simple holder for C{host} and C{port} information.
    c                 ó    — || _         || _        y )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y)ÚReverseProxyRequestTestsz+
    Tests for L{ReverseProxyRequest}.
    c                 ó$  — t        «       }t        |«      }t        «       }t        |d|«      }t	        dd«      |_        |j                  d«       |j                  ddd«       | j                  t        |j                  «      d«       | j                  |j                  d   d   d«       | j                  |j                  d   d   d«       |j                  d   d	   }| j                  |t        «       | j                  |j                  d
di«       y)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   r¶   rÛ   rj   r•   rÒ   r   rÓ   N)r   rI   r   r	   rå   r,   rÔ   rÖ   r   r¯   r   r   r   r    )r!   r(   r)   r%   rl   r,   s         r/   rÝ   z%ReverseProxyRequestTests.test_process  s÷   € ô 5Ó6ˆ	Ü˜yÓ)ˆÜ“/ˆÜ% g¨u°gÓ>ˆÜ& }°dÓ;ˆŒØ×Ñ˜!ÔØ×Ñ ¨°[ÔAð 	×Ñœ˜W×/Ñ/Ó0°!Ô4Ø×Ñ˜×+Ñ+¨AÑ.¨qÑ1°=ÔAØ×Ñ˜×+Ñ+¨AÑ.¨qÑ1°4Ô8ð ×$Ñ$ QÑ'¨Ñ*ˆØ×Ñ˜gÔ'9Ô:Ø×Ñ˜Ÿ™¨7°NÐ*CÕDr1   N)rC   rD   rE   rF   rÝ   rG   r1   r/   rè   rè     s   „ ñó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Ý +÷õ õ *Ý #Ý 2ôP9 ô P9÷f (ñ  (ôFxU�xô xUôv(
˜hô (
ôVI9˜ô I9÷Xñ ôE˜xõ Er1   