From 928cfd3950d80507c17b9d2d1f6544ef37bfc7de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gina=20H=C3=A4u=C3=9Fge?= Date: Sun, 1 Sep 2013 19:28:15 +0200 Subject: [PATCH] Added content length header to streamed output --- octoprint/server.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/octoprint/server.py b/octoprint/server.py index 7b960389..bd66439c 100644 --- a/octoprint/server.py +++ b/octoprint/server.py @@ -934,10 +934,10 @@ def _streamBinaryFile(filename, mimeType=None, asAttachment=False, attachmentFil if not os.path.exists(filename) or not os.path.isfile(filename): return app.make_response(("No such file: %s" % filename, 404, [])) - def generator(path): + def generator(path, chunkSize=4096): with open(path, "rb") as f: while True: - data = f.read(4096) + data = f.read(chunkSize) if not data: break yield data @@ -947,6 +947,7 @@ def _streamBinaryFile(filename, mimeType=None, asAttachment=False, attachmentFil if attachmentFilename is None: attachmentFilename = os.path.basename(filename) headers.add("Content-Disposition", "attachment", filename=attachmentFilename) + headers.add("Content-Length", os.stat(filename).st_size) if mimeType is None: mimeType = "application/octet-stream"