Index: src/fs.cr ================================================================== --- src/fs.cr +++ src/fs.cr @@ -3,10 +3,11 @@ require "uri" require "http" require "option_parser" require "yaml" require "logger" +require "mime" # Class for reading configuration information from fs.yml. class Config # Required settings @@ -93,10 +94,13 @@ @config = config @root = config.root @server = uninitialized HTTP::Server end + # This gets called if HTTP::StaticFileHandler can't find a file. + # The most common case is a directory path, in which case + # we look for index.html in that directory. def process_request(context : HTTP::Server::Context) request = context.request request_path = request.path method = request.method @@ -105,11 +109,11 @@ path = File.join(@root, request_path) if Dir.exists?(path) path = File.join(path, "index.html") end if File.exists?(path) - content_type = `file -b --mime-type #{path}`.strip + content_type = MIME.from_filename(path) context.response.content_type = content_type MyLog.info "Serving #{path}, content type #{content_type}" File.open(path) { |file| IO.copy(file, context.response) } else MyLog.error "No such file #{path}"