lib/slinky/server.rb in slinky-0.8.2 vs lib/slinky/server.rb in slinky-0.8.3

- old
+ new

@@ -46,12 +46,10 @@ if file.is_a? ManifestDir file = manifest.find_by_path(path + "/index.html").first path += "/index.html" end - resp.content_type MIME::Types.type_for(path).first.to_s - if file # They're requesting the source file and we should not # compile it (but still process directives) compile = !(file.source.end_with?(path) && file.source) handle_file(resp, file, compile) @@ -59,10 +57,18 @@ path = p[0] == "/" ? p[1..-1] : p self.process_path(resp, path, true) else not_found resp end + + type = MIME::Types.type_for(path).first.to_s + if resp.content.encoding.to_s == "UTF-8" + type += "; charset=utf-8" + end + + resp.content_type type + resp end # Produces nice error output for various kinds of formats def self.format_error_output resp, mf, error @@ -114,10 +120,10 @@ def self.serve_file resp, path if File.exists?(path) && !File.directory?(path) size = File.size(path) _, _, extension = path.match(EXTENSION_REGEX).to_a # File reading code from rack/file.rb - File.open path do |file| + File.open(path, "rb") do |file| resp.content = "" while size > 0 part = file.read([8192, size].min) break unless part size -= part.length