[Twisted-Python] no 'headers' in server.Request instance problem

with mozilla build Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.8) Gecko/20020206,build 2002020615 sending a request to a quixote/twisted server (actually a modified Andrew Kuchling Example), I get the following error Installing SelectReactor, since unspecified. __main__.QuixoteFactory starting on 8098 Traceback (most recent call last): File "/sw/release/python/lib/python2.2/site-packages/twisted/internet/default.py", line 347, in doSelect why = getattr(selectable, method)() File "/sw/release/python/lib/python2.2/site-packages/twisted/internet/tcp.py", line 93, in doRead return self.protocol.dataReceived(data) File "/sw/release/python/lib/python2.2/site-packages/twisted/protocols/basic.py", line 161, in dataReceived self.lineReceived(line) File "/sw/release/python/lib/python2.2/site-packages/twisted/protocols/http.py", line 684, in lineReceived self.allHeadersReceived() File "/sw/release/python/lib/python2.2/site-packages/twisted/protocols/http.py", line 733, in allHeadersReceived self.persistent = self.checkPersistence(req, self.__version) File "/sw/release/python/lib/python2.2/site-packages/twisted/protocols/http.py", line 759, in checkPersistence request.setHeader('connection', 'close') File "/sw/release/python/lib/python2.2/site-packages/twisted/protocols/http.py", line 561, in setHeader self.headers[string.lower(k)] = v exceptions.AttributeError: QuixoteTWRequest instance has no attribute 'headers' The object QuixoteTWRequest is defined class QuixoteTWRequest (server.Request): ...... it looks to me like on some execution path thru http.py (dataReceived, lineReceived) etc etc the headers slot of the server.Request object doesnt get set. which would appear to mean requestReceived has not been called as this sets self.headers to an empty dict at least. The headers sent by the browser are :- Host: localhost:9999 User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:0.9.8) Gecko/20020206 Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1 Accept-Language: en-us Accept-Encoding: gzip, deflate, compress;q=0.9 Accept-Charset: ISO-8859-1, utf-8;q=0.66, *;q=0.66 Connection: close localhost.localdomain - - [12/Jun/2002 21:40:50] "GET / HTTP/1.1" 200 - I'm pretty new to Twisted, so I might be missing something here, but the script works with lynx and netscape 4.76. Jon

This is a bug (due to that "Connection: close" header from Mozilla). I fixed it in CVS - 0.18.1 will include a fixed version. Until then you can get the updated version of twisted/protocols/http.py from CVS (see instructions on website.) BTW - you don't need to use twisted.web.server.Request - since the refactor to HTTP you only need twisted.protocols.http.Request, no need to use twisted.web unless you are using it as a web framework.

I also added a unit test. Let that be a lesson to you all - you need Real Users to find all those endcases you're certain you've written tests for - I'd written a test for the persistent connection algorithm but forgotten to simulate a real HTTP test request for that specific case. Bleh. /me goes to sleep

From: Itamar Shtull-Trauring <twisted@itamarst.org> Subject: Re: [Twisted-Python] no 'headers' in server.Request instance problem Date: Thu, 13 Jun 2002 01:37:41 +0200
BTW - you don't need to use twisted.web.server.Request - since the refactor to HTTP you only need twisted.protocols.http.Request, no need to use twisted.web unless you are using it as a web framework.
Actually you don't need to use Request at all. If you want this to work with other twisted.web servers, it would be best to structure your work as additions to Resource, not Request. What functionality are you adding at the Request level? -- | <`'> | Glyph Lefkowitz: Traveling Sorcerer | | < _/ > | Lead Developer, the Twisted project | | < ___/ > | http://www.twistedmatrix.com |
participants (3)
-
Glyph Lefkowitz
-
Itamar Shtull-Trauring
-
Jon Dyte