[Twisted-Python] HTTP versions

Andrew Dalke dalke at dalkescientific.com
Mon Jun 2 00:55:29 MDT 2003


I've been reviewing the http.py code.  It seems there's a bug in the
following, when there is an IE connect.

     def lineReceived(self, line):
         if self.__first_line:
             # if this connection is not persistent, drop any data which
             # the client (illegally) sent after the last request.
             if not self.persistent:
                 self.dataReceived = self.lineReceived = lambda *args: 
None
                 return

             # create a new Request object
             request = self.requestFactory(self, len(self.requests))
             self.requests.append(request)

             # IE sends an extraneous empty line (\r\n) after a POST 
request;
             # eat up such a line, but only ONCE
             if not line and self.__first_line == 1:
                 self.__first_line = 2
                 return


As written, IE with the bug will create two Request objects.

Here's a bugfix, which swaps the last two sections

     def lineReceived(self, line):
         if self.__first_line:
             # if this connection is not persistent, drop any data which
             # the client (illegally) sent after the last request.
             if not self.persistent:
                 self.dataReceived = self.lineReceived = lambda *args: 
None
                 return

             # IE sends an extraneous empty line (\r\n) after a POST 
request;
             # eat up such a line, but only ONCE
             if not line and self.__first_line == 1:
                 self.__first_line = 2
                 return

             # create a new Request object
             request = self.requestFactory(self, len(self.requests))
             self.requests.append(request)


					Andrew





More information about the Twisted-Python mailing list