[Twisted-web] How can I change the HTTP request to avoid gzip

Jean-Paul Calderone exarkun at divmod.com
Tue Dec 16 09:25:52 EST 2008

On Tue, 16 Dec 2008 15:57:18 +0200, Radu Dragusin <radudragusin at gmail.com> wrote:
>On Tue, Dec 16, 2008 at 2:20 PM, Jean-Paul Calderone <exarkun at divmod.com>wrote:
>> On Tue, 16 Dec 2008 05:31:45 +0200, Radu Dragusin <radudragusin at gmail.com>
>> wrote:
> [snip]
>>> class WordCountProxyRequest(proxy.ProxyRequest):
>>>   protocols = {'http': WordCountProxyClientFactory}
>>>   def __init__(self, wordCounter, *args):
>>>       self.wordCounter = wordCounter
>>>       proxy.ProxyRequest.__init__(self, *args)
>>> *    def process(self):
>>>       proxy.ProxyRequest.process(self)
>>>       print "received_headers", proxy.ProxyRequest.getAllHeaders(self)*
>the print above prints:
>received_headers: {'accept-language': 'en-us,en;q=0.5', 'accept-encoding':
>'gzip,deflate', 'keep-alive': '300', 'accept':
>'user-agent': 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:
>Gecko/2008111318 Ubuntu/8.10 (intrepid) Firefox/3.0.4', 'accept-charset':
>'ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'host': 'www.google.com', 'cookie':
>S=photos_html=6ScUGfd699g4Xuuh0FeizA; TZ=-120', 'cache-control':
>'max-age=0', 'proxy-connection': 'keep-alive'}
>these are the values I want to modify, the 'accept-encoding', to be
>specific. How can I do it?

Request has a received_headers attribute which refers to a dictionary.  You
can delete the "accept" key from it.  Make sure you do it before you call
the base process method, though:

    def process(self):
            del self.received_headers['accept']
        except KeyError:

Or, in Twisted 8.2, you can use a slightly better headers API:

    def process(self):


More information about the Twisted-web mailing list