Skip to content

Commit

Permalink
Better handle edge-cases in content-type ad disposition headers.
Browse files Browse the repository at this point in the history
  • Loading branch information
cekk committed Jun 18, 2024
1 parent 848278e commit e6d4326
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions src/redturtle/filesretriever/restapi/services/save_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand All @@ -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,
}
2 changes: 1 addition & 1 deletion test_plone52.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e6d4326

Please sign in to comment.