From 3e640c22a23f2494dc9546dd4703a3dc2682171b Mon Sep 17 00:00:00 2001 From: Robert <8934693+0x1eef@users.noreply.github.com> Date: Sun, 25 Jun 2023 21:21:00 -0300 Subject: [PATCH] server: add content-type based on path extname (#133) ### Summary Add content-type based on path extname using `Rack::Mime`. --- packages/ruby/server/lib/server/dir.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/ruby/server/lib/server/dir.rb b/packages/ruby/server/lib/server/dir.rb index 8397a3d..1262908 100644 --- a/packages/ruby/server/lib/server/dir.rb +++ b/packages/ruby/server/lib/server/dir.rb @@ -20,7 +20,11 @@ class Server::Dir def read(path) body = File.binread(path) - [{"Content-Length" => body.bytesize}, body.each_line] + [ + {"content-type" => Rack::Mime.mime_type(File.extname(path)), + "content-length" => body.bytesize}, + body.each_line + ] end def local_path(req_path) @@ -29,6 +33,6 @@ class Server::Dir end def not_found - [404, {"Content-Type" => "text/plain"}, ["The requested URL was not found"]] + [404, {"content-type" => "text/plain"}, ["The requested URL was not found"]] end end