Set the Last-Modified header when downloading from peers.
authorCameron Dale <camrdale@gmail.com>
Wed, 23 Apr 2008 23:12:29 +0000 (16:12 -0700)
committerCameron Dale <camrdale@gmail.com>
Wed, 23 Apr 2008 23:16:31 +0000 (16:16 -0700)
TODO
apt_p2p/PeerManager.py

diff --git a/TODO b/TODO
index 10dae92ff0dfe61703d9c153c1d083e184ea3b85..7d6ec4d16995df9bd832d23395f8e2448daa8b87 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,8 +1,6 @@
 Some last few things to do before release.
 
 - Handle/investigate the HTTP client pipeline errors
-- update the modtime of files downloaded from peers
-  - also set the Last-Modified header for the return to Apt
 
 Consider what happens when multiple requests for a file are received.
 
index 447e69759bcacd16f2d98f235447349479995776..7f63c974aadb7c48b12298433627611a20394a0b 100644 (file)
@@ -276,6 +276,7 @@ class FileDownload:
         self.compact_peers = compact_peers
         
         self.path = '/~/' + quote_plus(hash.expected())
+        self.defer = None
         self.mirror_path = None
         self.pieces = None
         self.started = False
@@ -518,11 +519,6 @@ class FileDownload:
 #            self.defer.callback(self.peerlist[0].get(self.path))
 #            return
         
-        # Start sending the return file
-        self.stream = GrowingFileStream(self.file, self.hash.expSize)
-        resp = Response(200, {}, self.stream)
-        self.defer.callback(resp)
-
         # Begin to download the pieces
         self.outstanding = 0
         self.nextFinish = 0
@@ -569,6 +565,19 @@ class FileDownload:
             if response.stream and response.stream.length:
                 stream.readAndDiscard(response.stream)
         else:
+            if self.defer:
+                # Start sending the return file
+                df = self.defer
+                self.defer = None
+                self.stream = GrowingFileStream(self.file, self.hash.expSize)
+
+                # Get the headers from the peer's response
+                headers = {}
+                if response.headers.hasHeader('last-modified'):
+                    headers['last-modified'] = response.headers.getHeader('last-modified')
+                resp = Response(200, {}, self.stream)
+                df.callback(resp)
+
             # Read the response stream to the file
             log.msg('Streaming piece %d from peer %r' % (piece, peer))
             if response.code == 206: