Commit c39b3b92 authored by Michael Tremer's avatar Michael Tremer

importer: Fix parsing gzipped content on invalid Content-Type header

RIPE seems to have misconfigured their webserver which now sends
application/octet-stream for all gzipped files instead of
application/x-gzip or similar which is what the importer would expect.

Instead of only checking the content type, we will now test whether we
see the gzip magic and try to decompress the file then.
Signed-off-by: default avatarMichael Tremer <michael.tremer@ipfire.org>
parent 8c6d516d
......@@ -148,11 +148,26 @@ class Downloader(object):
# Rewind the temporary file
t.seek(0)
gzip_compressed = False
# Fetch the content type
content_type = res.headers.get("Content-Type")
# Decompress any gzipped response on the fly
if content_type in ("application/x-gzip", "application/gzip"):
gzip_compressed = True
# Check for the gzip magic in case web servers send a different MIME type
elif t.read(2) == b"\x1f\x8b":
gzip_compressed = True
# Reset again
t.seek(0)
# Decompress the temporary file
if gzip_compressed:
log.debug("Gzip compression detected")
t = gzip.GzipFile(fileobj=t, mode="rb")
# Return the temporary file handle
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment