def send_dir_listing(base, dir, response)
base = HttpRequest.unescape(base)
base.chop! if base[-1] == "/"[-1]
if @listing_allowed
response.start(200) do |head,out|
head[Const::CONTENT_TYPE] = "text/html"
out << "<html><head><title>Directory Listing</title></head><body>"
Dir.entries(dir).each do |child|
next if child == "."
out << "<a href=\"#{base}/#{ HttpRequest.escape(child)}\">"
out << (child == ".." ? "Up to parent.." : child)
out << "</a><br/>"
end
out << "</body></html>"
end
else
response.start(403) do |head,out|
out.write("Directory listings not allowed")
end
end
end