[Twisted-Python] Twisted n00b question

Michal Migurski mike at stamen.com
Tue Jan 24 02:26:13 EST 2006


>> My second attempt: I found the Proxy class in the twisted.web docs,
>> which has this code snippet:
>>
>>     from twisted.protocols import http
>>     f = http.HTTPFactory()
>>     f.protocol = Proxy
>>
>> ...which is great, but I'm now I'm not sure what I need to do with
>> the "f" object to make it work in a .tac/twistd context. It seems
>> like should be able to add a callback in there someplace to intercept
>> the proxied requests and pick them apart, but I'm a little stuck.
>
> 'f' is a protocol factory. It exists to create protocol instances
> (proxy.Proxy) when something connects to a listening socket,  
> typically a
> TCP server.
>
> Here's a complete .tac file that runs a proxy on port 8080.
>
> {{{
> from twisted.application import internet, service
> from twisted.web import http, proxy
>
> application = service.Application('proxy')
>
> f = http.HTTPFactory()
> f.protocol = proxy.Proxy
> proxyService = internet.TCPServer(8080, f)
> proxyService.setServiceParent(application)
> }}}
>
> Hope that helps.

This is perfect.
I'm now subclassing Proxy, ProxyRequest, ProxyClientFactory and  
ProxyClient to get the results I want.

Thanks!

-mike.

----------------------------------------------------------------
michal migurski- mike at stamen.com
                  415.558.1610






More information about the Twisted-Python mailing list