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.
"""
if hash.expected() is None:
log.msg('Hash for %s was not found' % url)
"""
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))
else:
log.msg('Found hash %s for %s' % (hash.hexexpected(), url))
"""
if not locations:
log.msg('Failed to return file from cache: %s' % url)
"""
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
return
# Get the first possible location from the list
# Try the next possible location
self.getCachedFile(hash, req, url, d, locations)
# 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)
"""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
"""Start the download of the file.
The download will be from peers if the DHT lookup succeeded, or
@param values: the returned values from the DHT containing peer
download information
"""
@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))
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))