From 6280af2e405258cc353e7d6039f3066817398a45 Mon Sep 17 00:00:00 2001 From: Cris Ward Date: Fri, 19 Aug 2016 15:49:29 +0100 Subject: [PATCH] added mime types (#195) * added mime types Added some mime type for images. Very new to crystal so hopefully this is ok. Without this they default to octet, which just does a download * jpg to jpeg --- src/kemal/static_file_handler.cr | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/kemal/static_file_handler.cr b/src/kemal/static_file_handler.cr index 7a9bb81..f4115f8 100644 --- a/src/kemal/static_file_handler.cr +++ b/src/kemal/static_file_handler.cr @@ -9,5 +9,20 @@ module Kemal return call_next(context) if context.request.path.not_nil! == "/" super end + + def mime_type(path) + case File.extname(path) + when ".txt" then "text/plain" + when ".htm", ".html" then "text/html" + when ".css" then "text/css" + when ".js" then "application/javascript" + when ".png" then "image/png" + when ".jpg", ".jpeg" then "image/jpeg" + when ".gif" then "image/gif" + when ".svg" then "image/svg+xml" + else "application/octet-stream" + end + end + end end