Method: Mongrel::DirHandler#send_dir_listing
- Defined in:
- lib/mongrel/handlers.rb
#send_dir_listing(base, dir, response) ⇒ Object
Returns a simplistic directory listing if they’re enabled, otherwise a 403. Base is the base URI from the REQUEST_URI, dir is the directory to serve on the file system (comes from can_serve()), and response is the HttpResponse object to send the results on.
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/mongrel/handlers.rb', line 166 def send_dir_listing(base, dir, response) # take off any trailing / so the links come out right 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 |