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
This commit is contained in:
Cris Ward 2016-08-19 15:49:29 +01:00 committed by Serdar Dogruyol
parent 849eda06c8
commit 6280af2e40

View file

@ -9,5 +9,20 @@ module Kemal
return call_next(context) if context.request.path.not_nil! == "/" return call_next(context) if context.request.path.not_nil! == "/"
super super
end 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
end end