diff --git a/CHANGES.rst b/CHANGES.rst index 3e1f0af..7e07017 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -5,7 +5,8 @@ Changelog 1.0.1 (unreleased) ------------------ -- Nothing changed yet. +- Better handle edge-cases in content-type ad disposition headers. + [cekk] 1.0.0 (2021-12-27) diff --git a/src/redturtle/filesretriever/restapi/services/save_files.py b/src/redturtle/filesretriever/restapi/services/save_files.py index 01e9914..5b3015e 100644 --- a/src/redturtle/filesretriever/restapi/services/save_files.py +++ b/src/redturtle/filesretriever/restapi/services/save_files.py @@ -52,7 +52,7 @@ def fetch_and_create(self, urls): url["error"] = dict( error=translate( _( - u"Error creating file: ${message}", + "Error creating file: ${message}", mapping={"message": message}, ), context=self.request, @@ -115,12 +115,14 @@ def fetch_data(self, url): return dict(error=message) filename = "" if "Content-Disposition" in response.headers.keys(): - filename = re.findall( + re_find = re.findall( "filename=(.+)", response.headers["Content-Disposition"] - )[0] - else: + ) + if re_find: + filename = re_find[0] + if not filename: filename = response.url.split("/")[-1] - content_type = response.headers.get("Content-Type", "") + content_type = response.headers.get("Content-Type", "").split(";")[0] if content_type.startswith("text/html"): return dict( error=translate( @@ -135,5 +137,5 @@ def fetch_data(self, url): return { "filename": filename, "data": response.content, - "content-type": response.headers.get("Content-Type", ""), + "content-type": content_type, } diff --git a/test_plone52.cfg b/test_plone52.cfg index 616bcc3..095ecaa 100644 --- a/test_plone52.cfg +++ b/test_plone52.cfg @@ -11,7 +11,7 @@ update-versions-file = test_plone52.cfg plone.testing = 7.0.1 collective.recipe.vscode = >=0.1.6 importlib-metadata = 1.1.3 - +setuptools = # Added by buildout at 2021-12-05 23:24:52.274850 collective.recipe.vscode = 0.1.7 flake8 = 3.9.2