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

Make urls schemes more robust against changes #19898

Merged
merged 2 commits into from
Nov 15, 2024
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
17 changes: 7 additions & 10 deletions cura/CuraApplication.py
Original file line number Diff line number Diff line change
Expand Up @@ -1895,23 +1895,20 @@ def _openUrl(self, url: QUrl) -> None:
def on_finish(response):
content_disposition_header_key = QByteArray("content-disposition".encode())

if not response.hasRawHeader(content_disposition_header_key):
Logger.log("w", "Could not find Content-Disposition header in response from {0}".format(
model_url.url()))
# Use the last part of the url as the filename, and assume it is an STL file
filename = model_url.path().split("/")[-1] + ".stl"
else:
filename = model_url.path().split("/")[-1] + ".stl"

if response.hasRawHeader(content_disposition_header_key):
# content_disposition is in the format
# ```
# content_disposition attachment; "filename=[FILENAME]"
# content_disposition attachment; filename="[FILENAME]"
# ```
# Use a regex to extract the filename
content_disposition = str(response.rawHeader(content_disposition_header_key).data(),
encoding='utf-8')
content_disposition_match = re.match(r'attachment; filename="(?P<filename>.*)"',
content_disposition_match = re.match(r'attachment; filename=(?P<filename>.*)',
content_disposition)
assert content_disposition_match is not None
filename = content_disposition_match.group("filename")
if content_disposition_match is not None:
filename = content_disposition_match.group("filename").strip("\"")

tmp = tempfile.NamedTemporaryFile(suffix=filename, delete=False)
with open(tmp.name, "wb") as f:
Expand Down
Loading