[downloader.http] implement file-specific HTTP headers
This commit is contained in:
@@ -77,12 +77,15 @@ class HttpDownloader(DownloaderBase):
|
|||||||
time.sleep(min(2 ** (tries-1), 1800))
|
time.sleep(min(2 ** (tries-1), 1800))
|
||||||
tries += 1
|
tries += 1
|
||||||
|
|
||||||
|
headers = {}
|
||||||
# check for .part file
|
# check for .part file
|
||||||
filesize = pathfmt.part_size()
|
filesize = pathfmt.part_size()
|
||||||
if filesize:
|
if filesize:
|
||||||
headers = {"Range": "bytes={}-".format(filesize)}
|
headers["Range"] = "bytes={}-".format(filesize)
|
||||||
else:
|
# file-specific headers
|
||||||
headers = None
|
extra = pathfmt.kwdict.get("_http_headers")
|
||||||
|
if extra:
|
||||||
|
headers.update(extra)
|
||||||
|
|
||||||
# connect to (remote) source
|
# connect to (remote) source
|
||||||
try:
|
try:
|
||||||
|
|||||||
@@ -189,7 +189,7 @@ class ResultJob(job.DownloadJob):
|
|||||||
self._update_url(url)
|
self._update_url(url)
|
||||||
self._update_kwdict(kwdict)
|
self._update_kwdict(kwdict)
|
||||||
self._update_archive(kwdict)
|
self._update_archive(kwdict)
|
||||||
self._update_content(url)
|
self._update_content(url, kwdict)
|
||||||
self.format_filename(kwdict)
|
self.format_filename(kwdict)
|
||||||
|
|
||||||
def handle_directory(self, kwdict):
|
def handle_directory(self, kwdict):
|
||||||
@@ -217,9 +217,10 @@ class ResultJob(job.DownloadJob):
|
|||||||
self.archive_list.append(archive_id)
|
self.archive_list.append(archive_id)
|
||||||
self.archive_hash.update(archive_id.encode())
|
self.archive_hash.update(archive_id.encode())
|
||||||
|
|
||||||
def _update_content(self, url):
|
def _update_content(self, url, kwdict):
|
||||||
if self.content:
|
if self.content:
|
||||||
scheme = url.partition(":")[0]
|
scheme = url.partition(":")[0]
|
||||||
|
self.fileobj.kwdict = kwdict
|
||||||
self.get_downloader(scheme).download(url, self.fileobj)
|
self.get_downloader(scheme).download(url, self.fileobj)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user