Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python/grass/utils: fix checking server response content type/dispostion header to allow to download ZIP file. #4658

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion python/grass/utils/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"""Download and extract various archives"""

import os
import re
import shutil
import tarfile
import tempfile
Expand All @@ -23,6 +24,10 @@
from urllib.request import urlretrieve


reponse_content_type_header_pattern = re.compile(r"application/(zip|octet-stream)")
reponse_content_disposition_header_pattern = re.compile(r"attachment; filename=.*.zip$")


def debug(*args, **kwargs):
"""Print a debug message (to be used in this module only)

Expand Down Expand Up @@ -170,7 +175,13 @@ def download_and_extract(source, reporthook=None):
)
except URLError:
raise DownloadError(url_error_message.format(url=source))
if headers.get("content-type", "") != "application/zip":

if not re.search(
reponse_content_type_header_pattern, headers.get("content-type", "")
) and not re.search(
reponse_content_disposition_header_pattern,
headers.get("content-disposition", ""),
):
raise DownloadError(
_(
"Download of <{url}> failed or file <{name}> is not a ZIP file"
Expand Down
Loading