From 6b480d7e875cf93a8c41288df73cde521429e202 Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Thu, 5 Aug 2021 16:46:25 +0300 Subject: [PATCH] Fix file server `GET` response for gzipped data-files contains `Content-Encoding: gz` header, causing clients to automatically decompress the file --- fileserver/fileserver.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fileserver/fileserver.py b/fileserver/fileserver.py index f7987e9..f5d536b 100644 --- a/fileserver/fileserver.py +++ b/fileserver/fileserver.py @@ -1,5 +1,6 @@ """ A Simple file server for uploading and downloading files """ import json +import mimetypes import os from argparse import ArgumentParser from pathlib import Path @@ -48,8 +49,12 @@ def upload(): @app.route("/", methods=["GET"]) def download(path): as_attachment = "download" in request.args + + _, encoding = mimetypes.guess_type(os.path.basename(path)) + mimetype = "application/octet-stream" if encoding == "gzip" else None + response = send_from_directory( - app.config["UPLOAD_FOLDER"], path, as_attachment=as_attachment + app.config["UPLOAD_FOLDER"], path, as_attachment=as_attachment, mimetype=mimetype ) if config.get("fileserver.download.disable_browser_caching", False): headers = response.headers