[dl:http] implement '_http_signature' (#4902)
allows passing a function to validate a file's signature bytes, similar to '_http_validate'
This commit is contained in:
@@ -267,19 +267,24 @@ class HttpDownloader(DownloaderBase):
|
|||||||
|
|
||||||
content = response.iter_content(self.chunk_size)
|
content = response.iter_content(self.chunk_size)
|
||||||
|
|
||||||
|
validate_sig = kwdict.get("_http_signature")
|
||||||
|
validate_ext = (adjust_extension and
|
||||||
|
pathfmt.extension in SIGNATURE_CHECKS)
|
||||||
|
|
||||||
# check filename extension against file header
|
# check filename extension against file header
|
||||||
if adjust_extension and not offset and \
|
if not offset and (validate_ext or validate_sig):
|
||||||
pathfmt.extension in SIGNATURE_CHECKS:
|
|
||||||
try:
|
try:
|
||||||
file_header = next(
|
file_header = next(
|
||||||
content if response.raw.chunked
|
content if response.raw.chunked
|
||||||
else response.iter_content(16), b"")
|
else response.iter_content(16), b"")
|
||||||
except (RequestException, SSLError) as exc:
|
except (RequestException, SSLError) as exc:
|
||||||
msg = str(exc)
|
msg = str(exc)
|
||||||
output.stderr_write("\n")
|
|
||||||
continue
|
continue
|
||||||
if self._adjust_extension(pathfmt, file_header) and \
|
if validate_sig and not validate_sig(file_header):
|
||||||
pathfmt.exists():
|
msg = "Invalid file signature bytes"
|
||||||
|
continue
|
||||||
|
if validate_ext and self._adjust_extension(
|
||||||
|
pathfmt, file_header) and pathfmt.exists():
|
||||||
pathfmt.temppath = ""
|
pathfmt.temppath = ""
|
||||||
response.close()
|
response.close()
|
||||||
return True
|
return True
|
||||||
|
|||||||
Reference in New Issue
Block a user