]> git.mxchange.org Git - quix0rs-apt-p2p.git/blobdiff - apt_p2p/HTTPDownloader.py
Fixed a bug in the HTTP downloader that caused errors with some mirrors that always...
[quix0rs-apt-p2p.git] / apt_p2p / HTTPDownloader.py
index 55a818f1a135624306494c077db9ced72fca7b95..1a0752c4e087a46a8bd562634d986c34a897576f 100644 (file)
@@ -95,13 +95,18 @@ class LoggingHTTPClientProtocol(HTTPClientProtocol):
         return chanRequest.responseDefer
 
     def setReadPersistent(self, persist):
+        oldPersist = self.readPersistent
         self.readPersistent = persist
         if not persist:
             # Tell all requests but first to abort.
             lostRequests = self.inRequests[1:]
             del self.inRequests[1:]
             for request in lostRequests:
-                request.connectionLost(PipelineError('The pipelined connection was lost'))
+                request.connectionLost(PipelineError('Pipelined connection was closed.'))
+        elif (oldPersist is PERSIST_NO_PIPELINE and
+              persist is PERSIST_PIPELINE and
+              self.outRequest is None):
+            self.manager.clientPipelining(self)
 
     def connectionLost(self, reason):
         self.readPersistent = False
@@ -115,7 +120,7 @@ class LoggingHTTPClientProtocol(HTTPClientProtocol):
         del self.inRequests[1:]
         for request in lostRequests:
             if request is not None:
-                request.connectionLost(reason)
+                request.connectionLost(PipelineError('Pipelined connection was closed.'))
                 
 class Peer(ClientFactory):
     """A manager for all HTTP requests to a single peer.
@@ -353,8 +358,9 @@ class Peer(ClientFactory):
     def _processLastResponse(self):
         """Save the download time of the last request for speed calculations."""
         if self._lastResponse is not None:
-            now = datetime.now()
-            self._downloadSpeeds.append((now, now - self._lastResponse[0], self._lastResponse[1]))
+            if self._lastResponse[1] is not None:
+                now = datetime.now()
+                self._downloadSpeeds.append((now, now - self._lastResponse[0], self._lastResponse[1]))
             self._lastResponse = None
             
     def downloadSpeed(self):