Re: Deferred in proxy.ProxyClient.handleHeader (reformatted)

[email protected]
Newsgroups gmane.comp.python.twisted.web
Message-ID <20100528190911.2734.1088925821.divmod.xquotient.36@localhost.localdomain>
On 12:47 pm, [email protected] wrote:
>hi!
>
>(sorry, the formatting in my last mail got screwed up. hope this time 
>it works)
>
>i'm currently writing a reverse proxy with twisted and i've a problem 
>with a deferred function in my handleHeader method.
>
>the code looks simplified like this (http://pastie.org/981735):
>
>class MyProxyClient(proxy.ProxyClient):
>    @defer.inlineCallbacks
>    def handleHeader(self, key, value):
>        if key.lower() == 'location':
>            clientCreator = protocol.ClientCreator(reactor, Redis, db=3)
>            redis = yield clientCreator.connectTCP("localhost", 6379)
>            value = yield redis.get('myproxy:hashcode:%s' % value)
>        proxy.ProxyClient.handleHeader(self,key,value)
>
>
>as the handleHeader caller doesn't wait for a deferred to finish, the 
>location header is added after handleResponseEnd is already called and 
>therefore never makes it to the client.
>
>is there a way to convert the non-blocking redis call to a blocking 
>redis call?
>i know that there's a blocking client library for redis but i'd rather 
>use only txredis if possible.

The proxy isn't written to deal with what you want to do.  Converting 
the non-blocking call into a blocking one won't fix the problem, it'll 
just change it.

If you want to change the headers that pass through the proxy, you 
probably need to hook in at a different place, where an asynchronous 
operation won't mess things up.

More generally, `twisted.web.proxy` isn't really well suited for a 
rewriting proxy.  It's barely capable of functioning as a boring pass- 
through proxy.  If you'd like to make your application simpler, you 
might want to look at ways to make `twisted.web.proxy` more well suited 
to this task.

Jean-Paul
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.