From 882106d0e49e52164a898c1cc9f36d229b4257ac Mon Sep 17 00:00:00 2001 From: Cameron Dale Date: Thu, 17 Apr 2008 18:15:35 -0700 Subject: [PATCH] Remove some headers Apt sets before returning full requests from the server. Otherwise the streaming will be interrupted or changed by Twisted's modification of responses before sending (e.g. sending 304's based on 'If-Modified-Since' and 'Last-Modified' headers). The streaming is currently needed though to load the file in the cache. --- apt_p2p/apt_p2p.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/apt_p2p/apt_p2p.py b/apt_p2p/apt_p2p.py index af7790a..e3a8af2 100644 --- a/apt_p2p/apt_p2p.py +++ b/apt_p2p/apt_p2p.py @@ -252,7 +252,7 @@ class AptP2P(protocol.Factory): """ if hash.expected() is None: log.msg('Hash for %s was not found' % url) - self.lookupHash_done([], hash, url, d) + self.lookupHash_done([], req, hash, url, d) else: log.msg('Found hash %s for %s' % (hash.hexexpected(), url)) @@ -270,7 +270,7 @@ class AptP2P(protocol.Factory): """ if not locations: log.msg('Failed to return file from cache: %s' % url) - self.lookupHash(hash, url, d) + self.lookupHash(req, hash, url, d) return # Get the first possible location from the list @@ -301,14 +301,14 @@ class AptP2P(protocol.Factory): # Try the next possible location self.getCachedFile(hash, req, url, d, locations) - def lookupHash(self, hash, url, d): + def lookupHash(self, req, hash, url, d): """Lookup the hash in the DHT.""" log.msg('Looking up hash in DHT for file: %s' % url) key = hash.expected() lookupDefer = self.dht.getValue(key) - lookupDefer.addBoth(self.lookupHash_done, hash, url, d) + lookupDefer.addBoth(self.lookupHash_done, req, hash, url, d) - def lookupHash_done(self, values, hash, url, d): + def lookupHash_done(self, values, req, hash, url, d): """Start the download of the file. The download will be from peers if the DHT lookup succeeded, or @@ -318,6 +318,11 @@ class AptP2P(protocol.Factory): @param values: the returned values from the DHT containing peer download information """ + # Remove some headers Apt sets in the request + req.headers.removeHeader('If-Modified-Since') + req.headers.removeHeader('Range') + req.headers.removeHeader('If-Range') + if not isinstance(values, list) or not values: if not isinstance(values, list): log.msg('DHT lookup for %s failed with error %r' % (url, values)) -- 2.39.5