From 699e224bc7f0bf7e4e3d86e388c3813de22d55ca Mon Sep 17 00:00:00 2001 From: Florian Festi Date: Sat, 17 Aug 2019 23:50:11 +0200 Subject: [PATCH] Add Content-Disposition header to have browsers download everything but SVGs It also downloads svg_Ponoko files as they cannot really be viewed in the browser. Related: #164 Thanks to Tagej for suggesting this! --- scripts/boxesserver | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/boxesserver b/scripts/boxesserver index 4c1e36f..fce6e55 100755 --- a/scripts/boxesserver +++ b/scripts/boxesserver @@ -426,10 +426,16 @@ b""" [('Content-type', 'text/plain; charset=utf-8')]) return([b"Server Error\n\n", str(e).encode("utf-8")]) - start_response(status, - box.formats.http_headers.get( - box.format, - [('Content-type', 'application/unknown; charset=utf-8')])) + http_headers = box.formats.http_headers.get( + box.format, + [('Content-type', 'application/unknown; charset=utf-8')]) + + if box.format != "svg": + extension = box.format + if extension == "svg_Ponoko": + extension = "svg" + http_headers.append(('Content-Disposition', 'attachment; filename="%s.%s"' % (box.__class__.__name__, extension))) + start_response(status, http_headers) result = open(box.output).readlines() os.close(fd) os.remove(box.output)