From 80399176ed66dc4d5c5ce6181648f75042910edd Mon Sep 17 00:00:00 2001 From: Cameron Dale Date: Wed, 23 Apr 2008 16:12:29 -0700 Subject: [PATCH] Set the Last-Modified header when downloading from peers. --- TODO | 2 -- apt_p2p/PeerManager.py | 19 ++++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/TODO b/TODO index 10dae92..7d6ec4d 100644 --- 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. diff --git a/apt_p2p/PeerManager.py b/apt_p2p/PeerManager.py index 447e697..7f63c97 100644 --- a/apt_p2p/PeerManager.py +++ b/apt_p2p/PeerManager.py @@ -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: -- 2.39.2