server: add content-type based on path extname (#133)

### Summary

Add content-type based on path extname using `Rack::Mime`.
This commit is contained in:
Robert 2023-06-25 21:21:00 -03:00 committed by GitHub
parent bf1558eeb0
commit 3e640c22a2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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