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:
parent
bf1558eeb0
commit
3e640c22a2
1 changed files with 6 additions and 2 deletions
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue