def _call(env)
if env["PATH_INFO"].include? ".."
body = "Forbidden\n"
size = body.respond_to?(:bytesize) ? body.bytesize : body.size
return [403, {"Content-Type" => "text/plain","Content-Length" => size.to_s}, [body]]
end
@path = F.join(@root, Utils.unescape(env["PATH_INFO"]))
ext = F.extname(@path)[1..-1]
if F.file?(@path) && F.readable?(@path)
[200, {
"Last-Modified" => F.mtime(@path).httpdate,
"Content-Type" => MIME_TYPES[ext] || "text/plain",
"Content-Length" => F.size(@path).to_s
}, self]
else
body = "File not found: #{env["PATH_INFO"]}\n"
size = body.respond_to?(:bytesize) ? body.bytesize : body.size
[404, {"Content-Type" => "text/plain", "Content-Length" => size.to_s}, [body]]
end
end