X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=apt_p2p%2Fapt_p2p.py;h=e3a8af248257c0e922dee672cae3fffbdcb1b045;hb=882106d0e49e52164a898c1cc9f36d229b4257ac;hp=af7790a7bb6ec06165cdfd552b27cba988c681b0;hpb=e848bee6cd8bd9ba754a21c3aff835f86d9c1aee;p=quix0rs-apt-p2p.git 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))