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']))
if F.exist?(@path) and F.readable?(@path)
if F.file?(@path)
return @app.call(env)
elsif F.directory?(@path)
@files = [['../','Parent Directory','','','']]
sName, pInfo = env.values_at('SCRIPT_NAME', 'PATH_INFO')
Dir.entries(@path).sort.each do |file|
next if file[0] == ?.
fl = F.join(@path, file)
sz = F.size(fl)
url = F.join(sName, pInfo, file)
type = F.directory?(fl) ? 'directory' :
MIME_TYPES.fetch(F.extname(file)[1..-1],'unknown')
size = (type!='directory' ? (sz<10240 ? "#{sz}B" : "#{sz/1024}KB") : '-')
mtime = F.mtime(fl).httpdate
@files << [ url, file, size, type, mtime ]
end
return [ 200, {'Content-Type'=>'text/html'}, self ]
end
end
body = "Entity not found: #{env["PATH_INFO"]}\n"
size = body.respond_to?(:bytesize) ? body.bytesize : body.size
return [404, {"Content-Type" => "text/plain", "Content-Length" => size.to_s}, [body]]
end