166: def send_dir_listing(base, dir, response)
167:
168: base = HttpRequest.unescape(base)
169: base.chop! if base[-1] == "/"[-1]
170:
171: if @listing_allowed
172: response.start(200) do |head,out|
173: head[Const::CONTENT_TYPE] = "text/html"
174: out << "<html><head><title>Directory Listing</title></head><body>"
175: Dir.entries(dir).each do |child|
176: next if child == "."
177: out << "<a href=\"#{base}/#{ HttpRequest.escape(child)}\">"
178: out << (child == ".." ? "Up to parent.." : child)
179: out << "</a><br/>"
180: end
181: out << "</body></html>"
182: end
183: else
184: response.start(403) do |head,out|
185: out.write("Directory listings not allowed")
186: end
187: end
188: end