+
    üÐj“&  ã                   ó   € R t ^ RIHtHtHt ^ RIHt ^ RIH	t	 ^ RI
HtHtHtHt ^ RIHt ^ RIHt  ! R R]4      t ! R	 R
]	4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      t ! R R]4      tR# )aT  
Simplistic HTTP proxy support.

This comes in two main variants - the Proxy and the ReverseProxy.

When a Proxy is in use, a browser trying to connect to a server (say,
www.yahoo.com) will be intercepted by the Proxy, and the proxy will covertly
connect to the server, and return the result.

When a ReverseProxy is in use, the client connects directly to the ReverseProxy
(say, www.yahoo.com) which farms off the request to one of a pool of servers,
and returns the result.

Normally, a Proxy is used on the client end of an Internet connection, while a
ReverseProxy is used on the server end.
)ÚquoteÚurlparseÚ
urlunparse©Úreactor)ÚClientFactory)Ú_QUEUED_SENTINELÚHTTPChannelÚ
HTTPClientÚRequest)ÚResource)ÚNOT_DONE_YETc                   óL   a € ] tR t^t o RtRtR tR tR tR t	R t
R tR	tV tR
# )ÚProxyClientz¥
Used by ProxyClientFactory to implement a simple web proxy.

@ivar _finished: A flag which indicates whether or not the original request
    has been finished yet.
Fc                ó„   € W`n         Wn        W n        R V9   d   VR  RVR&   VP                  RR4       W@n        WPn        R# )s   proxy-connections   closes
   connections
   keep-aliveN)ÚfatherÚcommandÚrestÚpopÚheadersÚdata©Úselfr   r   Úversionr   r   r   s   &&&&&&&Ú3/usr/lib/python3/dist-packages/twisted/web/proxy.pyÚ__init__ÚProxyClient.__init__)   sD   € ØŒØŒØŒ	Ø 'Ô)ØÐ+Ð,Ø!)ˆ�ÑØ�‰�M 4Ô(ØŒØŽ	ó    c                ó$  € V P                  V P                  V P                  4       V P                  P	                  4        F  w  rV P                  W4       K  	  V P                  4        V P                  P                  V P                  4       R # ©N)
ÚsendCommandr   r   r   ÚitemsÚ
sendHeaderÚ
endHeadersÚ	transportÚwriter   )r   ÚheaderÚvalues   &  r   ÚconnectionMadeÚProxyClient.connectionMade4   s_   € Ø×Ñ˜Ÿ™ t§y¡yÔ1Ø!Ÿ\™\×/Ñ/Ö1‰MˆFØ�O‰O˜FÖ*ñ 2à�‰ÔØ�‰×Ñ˜TŸY™YÖ'r   c                óP   € V P                   P                  \        V4      V4       R # r   )r   ÚsetResponseCodeÚint)r   r   ÚcodeÚmessages   &&&&r   ÚhandleStatusÚProxyClient.handleStatus;   s   € Ø�‰×#Ñ#¤C¨£I¨wÖ7r   c                óÊ   € VP                  4       R9   d)   V P                  P                  P                  W.4       R# V P                  P                  P	                  W4       R# )ó   serverN)r2   s   dates   content-type)Úlowerr   ÚresponseHeadersÚsetRawHeadersÚaddRawHeader)r   Úkeyr'   s   &&&r   ÚhandleHeaderÚProxyClient.handleHeader>   sE   € ð
 �9‰9‹;Ð?Ô?Ø�K‰K×'Ñ'×5Ñ5°c¸7ÖCà�K‰K×'Ñ'×4Ñ4°SÖ@r   c                ó<   € V P                   P                  V4       R # r   )r   r%   )r   Úbuffers   &&r   ÚhandleResponsePartÚProxyClient.handleResponsePartH   s   € Ø�‰×Ñ˜&Ö!r   c                ó¤   € V P                   '       g>   RV n         V P                  P                  4        V P                  P	                  4        R# R# )z…
Finish the original request, indicating that the response has been
completely written to it, and disconnect the outgoing transport.
TN)Ú	_finishedr   Úfinishr$   ÚloseConnection)r   s   &r   ÚhandleResponseEndÚProxyClient.handleResponseEndK   s9   € ð
 �~�~ˆ~Ø!ˆDŒNØ�K‰K×ÑÔ Ø�N‰N×)Ñ)Ö+ñ r   )r?   r   r   r   r   r   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r?   r   r(   r/   r8   r<   rB   Ú__static_attributes__Ú__classdictcell__©Ú__classdict__s   @r   r   r      s5   ø‡ € ñð €Iò	ò(ò8òAò"÷,ð ,r   r   c                   ó:   a € ] tR t^Vt o Rt]tR tR tR t	Rt
V tR# )ÚProxyClientFactoryz7
Used by ProxyRequest to implement a simple web proxy.
c                óN   € W`n         Wn        W n        W@n        WPn        W0n        R # r   )r   r   r   r   r   r   r   s   &&&&&&&r   r   ÚProxyClientFactory.__init__^   s    € ØŒØŒØŒ	ØŒØŒ	ØŽr   c                ó¦   € V P                  V P                  V P                  V P                  V P                  V P
                  V P                  4      # r   )Úprotocolr   r   r   r   r   r   )r   Úaddrs   &&r   ÚbuildProtocolÚ ProxyClientFactory.buildProtocolf   s8   € Ø�}‰}Ø�L‰L˜$Ÿ)™) T§\¡\°4·<±<ÀÇÁÈDÏKÉKó
ð 	
r   c                óô   € V P                   P                  RR4       V P                   P                  P                  RR4       V P                   P	                  R4       V P                   P                  4        R# )zP
Report a connection failure in a response to the incoming request as
an error.
iõ  s   Gateway errors   Content-Types	   text/htmls   <H1>Could not connect</H1>N)r   r+   r4   r6   r%   r@   )r   Ú	connectorÚreasons   &&&r   ÚclientConnectionFailedÚ)ProxyClientFactory.clientConnectionFailedk   sV   € ð
 	�‰×#Ñ# CÐ)9Ô:Ø�‰×#Ñ#×0Ñ0°À,ÔOØ�‰×ÑÐ7Ô8Ø�‰×ÑÖr   )r   r   r   r   r   r   N)rD   rE   rF   rG   rH   r   rR   r   rT   rY   rI   rJ   rK   s   @r   rN   rN   V   s%   ø‡ € ñð
 €Hòò
÷
ð r   rN   c                   óH   a € ] tR t^vt o RtR]/tR^P/t]]	3R lt
R tRtV tR# )ÚProxyRequestz³
Used by Proxy to implement a simple web proxy.

@ivar reactor: the reactor used to create connections.
@type reactor: object providing L{twisted.internet.interfaces.IReactorTCP}
s   httpc                ó@   € \         P                  ! WV4       W0n        R # r   ©r   r   r   ©r   ÚchannelÚqueuedr   s   &&&&r   r   ÚProxyRequest.__init__�   ó   € Ü×Ò˜¨Ô/ØŽr   c                ó°  € \        V P                  4      pV^ ,          pV^,          P                  R4      pV P                  V,          pRV9   d   VP	                  R4      w  r4\        V4      p\        RVR,          ,           4      pV'       g
   VR,           pV P                  V,          pV P                  4       P                  4       pRV9  d   VP                  R4      VR&   V P                  P                  ^ ^ 4       V P                  P                  4       pV! V P                  WPP                  WxV 4      p	V P                   P#                  W4V	4       R# )é    ÚasciiÚ::é   NNó   /ó   hostN)r   r   )r   ÚuriÚdecodeÚportsÚsplitr,   r   Ú	protocolsÚgetAllHeadersÚcopyÚencodeÚcontentÚseekÚreadÚmethodÚclientprotor   Ú
connectTCP)
r   ÚparsedrR   ÚhostÚportr   Úclass_r   ÚsÚclientFactorys
   &         r   ÚprocessÚProxyRequest.process…   s  € Ü˜$Ÿ(™(Ó#ˆØ˜!•9ˆØ�a�y×Ñ Ó(ˆØ�z‰z˜(Õ#ˆØ�$Œ;ØŸ™ C›‰JˆDÜ�t“9ˆDÜ˜* v¨b¥zÕ1Ó2ˆßØ˜$•;ˆDØ—‘ Õ)ˆØ×$Ñ$Ó&×+Ñ+Ó-ˆØ˜'Ô!Ø#Ÿ{™{¨7Ó3ˆG�GÑØ�‰×Ñ˜!˜QÔØ�L‰L×ÑÓˆÙ˜tŸ{™{¨D×2BÑ2BÀGÐPTÓUˆØ�‰×Ñ ¨MÖ:r   r   N)rD   rE   rF   rG   rH   rN   ro   rm   r   r   r   r   rI   rJ   rK   s   @r   r\   r\   v   s4   ø‡ € ñð Ð,Ð-€IØ�bˆM€Eà'7Àô ÷;ð ;r   r\   c                   ó   € ] tR t^štRt]tRtR# )ÚProxyaK  
This class implements a simple web proxy.

Since it inherits from L{twisted.web.http.HTTPChannel}, to use it you
should do something like this::

    from twisted.web import http
    f = http.HTTPFactory()
    f.protocol = Proxy

Make the HTTPFactory a listener on a port as per usual, and you have
a fully-functioning web proxy!
© N)rD   rE   rF   rG   rH   r\   ÚrequestFactoryrI   rƒ   r   r   r‚   r‚   š   s   † ñð "„Nr   r‚   c                   ó<   a € ] tR t^¬t o Rt]t]]3R lt	R t
RtV tR# )ÚReverseProxyRequestaP  
Used by ReverseProxy to implement a simple reverse proxy.

@ivar proxyClientFactoryClass: a proxy client factory class, used to create
    new connections.
@type proxyClientFactoryClass: L{ClientFactory}

@ivar reactor: the reactor used to create connections.
@type reactor: object providing L{twisted.internet.interfaces.IReactorTCP}
c                ó@   € \         P                  ! WV4       W0n        R # r   r^   r_   s   &&&&r   r   ÚReverseProxyRequest.__init__º   rc   r   c                óÄ  € V P                   P                  RV P                  P                  P	                  R4      .4       V P                  V P                  V P                  V P                  V P                  4       V P                  P                  4       V 4      pV P                  P                  V P                  P                  V P                  P                  V4       R# )z•
Handle this request by connecting to the proxied server and forwarding
it there, then forwarding the response back as the response to this
request.
rj   rf   N)ÚrequestHeadersr5   Úfactoryrz   rr   ÚproxyClientFactoryClassrv   rk   rw   rp   rs   ru   r   rx   r{   )r   r~   s   & r   r   ÚReverseProxyRequest.process¾   s¤   € ð 	×Ñ×)Ñ)¨'°D·L±L×4EÑ4E×4LÑ4LÈWÓ4UÐ3VÔWØ×4Ñ4Ø�K‰KØ�H‰HØ×ÑØ×ÑÓ Ø�L‰L×ÑÓØó
ˆð 	�‰×Ñ §¡× 1Ñ 1°4·<±<×3DÑ3DÀmÖTr   r   N)rD   rE   rF   rG   rH   rN   rŒ   r   r   r   r   rI   rJ   rK   s   @r   r†   r†   ¬   s(   ø‡ € ñ	ð 1Ðà'7Àô ÷Uð Ur   r†   c                   ó   € ] tR t^ÐtRt]tRtR# )ÚReverseProxyzc
Implements a simple reverse proxy.

For details of usage, see the file examples/reverse-proxy.py.
rƒ   N)rD   rE   rF   rG   rH   r†   r„   rI   rƒ   r   r   r�   r�   Ð   s   † ñð )„Nr   r�   c                   ó@   a € ] tR t^Út o Rt]t]3R ltR t	R t
RtV tR# )ÚReverseProxyResourcea´  
Resource that renders the results gotten from another server

Put this resource in the tree to cause everything below it to be relayed
to a different server.

@ivar proxyClientFactoryClass: a proxy client factory class, used to create
    new connections.
@type proxyClientFactoryClass: L{ClientFactory}

@ivar reactor: the reactor used to create connections.
@type reactor: object providing L{twisted.internet.interfaces.IReactorTCP}
c                ób   € \         P                  ! V 4       Wn        W n        W0n        W@n        R# )aý  
@param host: the host of the web server to proxy.
@type host: C{str}

@param port: the port of the web server to proxy.
@type port: C{port}

@param path: the base path to fetch data from. Note that you shouldn't
    put any trailing slashes in it, it will be added automatically in
    request. For example, if you put B{/foo}, a request on B{/bar} will
    be proxied to B{/foo/bar}.  Any required encoding of special
    characters (such as " " or "/") should have been done already.

@type path: C{bytes}
N)r   r   rz   r{   Úpathr   )r   rz   r{   r“   r   s   &&&&&r   r   ÚReverseProxyResource.__init__ë   s&   € ô  	×Ò˜$ÔØŒ	ØŒ	ØŒ	ØŽr   c           
     ó¾   € \        V P                  V P                  V P                  R,           \	        VRR7      P                  R4      ,           V P                  4      # )zŸ
Create and return a proxy resource with the same proxy configuration
as this one, except that its path also contains the segment given by
C{path} at the end.
ri   r   )Úsafezutf-8)r‘   rz   r{   r“   Úurlquoterr   r   )r   r“   Úrequests   &&&r   ÚgetChildÚReverseProxyResource.getChild  sI   € ô $Ø�I‰IØ�I‰IØ�I‰I˜Õœx¨°3Ô7×>Ñ>¸wÓGÕGØ�L‰Ló	
ð 	
r   c                ó°  € V P                   ^P8X  d   V P                  pMRV P                  V P                   3,          pVP                  P                  RVP	                  R4      .4       VP
                  P                  ^ ^ 4       \        VP                  4      ^,          pV'       d   V P                  R,           V,           pMV P                  pV P                  VP                  VVP                  VP                  4       VP
                  P                  4       V4      pV P                  P!                  V P                  V P                   V4       \"        # )z:
Render a request by forwarding it to the proxied server.
z%s:%drj   rf   ó   ?)r{   rz   rŠ   r5   rr   rs   rt   r   rk   r“   rŒ   rv   rw   rp   ru   r   rx   r   )r   r˜   rz   Úqsr   r~   s   &&    r   ÚrenderÚReverseProxyResource.render  sÿ   € ð �9‰9˜Œ?Ø—9‘9‰Dà˜dŸi™i¨¯©Ð3Õ3ˆDØ×Ñ×,Ñ,¨W°t·{±{À7Ó7KÐ6LÔMØ�‰×Ñ˜Q Ô"Ü�g—k‘kÓ" 1Õ%ˆßØ—9‘9˜tÕ# bÕ(‰Dà—9‘9ˆDØ×4Ñ4Ø�N‰NØØ×ÑØ×!Ñ!Ó#Ø�O‰O× Ñ Ó"Øó
ˆð 	�‰×Ñ §	¡	¨4¯9©9°mÔDÜÐr   )rz   r“   r{   r   N)rD   rE   rF   rG   rH   rN   rŒ   r   r   r™   rž   rI   rJ   rK   s   @r   r‘   r‘   Ú   s)   ø‡ € ñð 1Ðà18ô ò,
÷ð r   r‘   N)rH   Úurllib.parser   r—   r   r   Útwisted.internetr   Útwisted.internet.protocolr   Útwisted.web.httpr   r	   r
   r   Útwisted.web.resourcer   Útwisted.web.serverr   r   rN   r\   r‚   r†   r�   r‘   rƒ   r   r   Ú<module>r¦      s�   ðñ
÷" AÑ @å $Ý 3ß OÓ OÝ )Ý +ô4,�*ô 4,ôn˜ô ô@!;�7ô !;ôH"ˆKô "ô$!U˜'ô !UôH)�;ô )ôN˜8ö Nr   