twisted.web2.client cuts responses short if they are not in chunked encoding and do not have a Content-Length header. I have attached a patch that fixes this bug. I am posting it to the list because I couldn't register on the site to post it to the bug tracker.

diff -r -C 3 TwistedWeb2-svn20071201.orig/twisted/web2/channel/http.py 
TwistedWeb2-svn20071201/twisted/web2/channel/http.py
*** TwistedWeb2-svn20071201.orig/twisted/web2/channel/http.py   Sat Dec  1 
04:10:51 2007
--- TwistedWeb2-svn20071201/twisted/web2/channel/http.py        Wed Mar 26 
03:33:09 2008
***************
*** 163,176 ****
              self.handleContentChunk(data[:self.length])
              extraneous = data[self.length:]
              channel = self.channel # could go away from allContentReceived.
!             if not self.chunkedIn:
!                 self.allContentReceived()
!             else:
!                 # NOTE: in chunked mode, self.length is the size of the 
current chunk,
!                 # so we still have more to read.
!                 self.chunkedIn = 2 # Read next chunksize
              
!             channel.setLineMode(extraneous)
  
      def headerReceived(self, line):
          """Store this header away. Check for too much header data
--- 163,177 ----
              self.handleContentChunk(data[:self.length])
              extraneous = data[self.length:]
              channel = self.channel # could go away from allContentReceived.
!             if not (self.length is None and not self.chunkedIn and 
self.parseCloseAsEnd):
!                 if not self.chunkedIn:
!                     self.allContentReceived()
!                 else:
!                     # NOTE: in chunked mode, self.length is the size of the 
current chunk,
!                     # so we still have more to read.
!                     self.chunkedIn = 2 # Read next chunksize
              
!                 channel.setLineMode(extraneous)
  
      def headerReceived(self, line):
          """Store this header away. Check for too much header data
diff -r -C 3 TwistedWeb2-svn20071201.orig/twisted/web2/client/http.py 
TwistedWeb2-svn20071201/twisted/web2/client/http.py
*** TwistedWeb2-svn20071201.orig/twisted/web2/client/http.py    Sat Dec  1 
04:11:46 2007
--- TwistedWeb2-svn20071201/twisted/web2/client/http.py Wed Mar 26 03:15:48 2008
***************
*** 8,13 ****
--- 8,14 ----
  
  from zope.interface import implements
  
+ from twisted.internet.error import ConnectionDone
  from twisted.internet.defer import Deferred
  from twisted.protocols.basic import LineReceiver
  from twisted.protocols.policies import TimeoutMixin
***************
*** 165,171 ****
          self._error(ProtocolError(text))
  
      def connectionLost(self, reason):
!         self._error(reason)
  
      def gotInitialLine(self, initialLine):
          parts = initialLine.split(' ', 2)
--- 166,177 ----
          self._error(ProtocolError(text))
  
      def connectionLost(self, reason):
!         # If the response was non-chunked and of indeterminate length, treat 
the
!         # connection being closed cleanly as the end of the response
!         if self.length is None and not self.chunkedIn and 
reason.check(ConnectionDone):
!             self.allContentReceived()
!         else:
!             self._error(reason)
  
      def gotInitialLine(self, initialLine):
          parts = initialLine.split(' ', 2)
_______________________________________________
Twisted-web mailing list
[email protected]
http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-web

Reply via email to