From 3a09c47ef0eecbf14450bbc1bc6324ac1c76c9f0 Mon Sep 17 00:00:00 2001 From: Florian Mounier Date: Mon, 13 Feb 2017 15:10:54 +0100 Subject: [PATCH] Fix #132 --- butterfly/routes.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/butterfly/routes.py b/butterfly/routes.py index 3c3beb3..6a9414b 100644 --- a/butterfly/routes.py +++ b/butterfly/routes.py @@ -108,7 +108,19 @@ class ThemeStatic(Route): raise tornado.web.HTTPError(403) if os.path.exists(fn): - self.set_header("Content-Type", guess_type(fn)[0]) + type = guess_type(fn)[0] + if type is None: + # Fallback if there's no mimetypes on the system + type = { + 'png': 'image/png', + 'jpg': 'image/jpeg', + 'jpeg': 'image/jpeg', + 'gif': 'image/gif', + 'woff': 'application/font-woff', + 'ttf': 'application/x-font-ttf' + }.get(fn.split('.')[-1], 'text/plain') + + self.set_header("Content-Type", type) with open(fn, 'rb') as s: while True: data = s.read(16384)