[Mongrel] DirHandler in surplus slashing / unrequited unescaping

carmen _ at whats-your.name
Mon Aug 7 13:03:15 EDT 2006

im using Mongrels to serve up /usr/portage/packages for other gentoo boxen. since i guess im the guinea pig with the DirHandler, ran into a couple issues:

first, the client showed no files in the remote binhost, turns out the DirHandler was adding a trailing "/" to every filename, presumably making the client think they were directories, not files. attached is a patch which fixes this behavior..

so now portage gets a bit further, and starts showing the normal xxxxoxxxx cache hit/miss line, and generating a lot of http traffic. eventually this fails, and mongrel stderr says:

Mon Aug 07 12:42:02 EDT 2006: BAD CLIENT ( Invalid HTTP format, parsing fails.

in ngrep port 80, the last request is this:

T -> [AP]
  GET /files/usr/portage/packages/All//gtk -2.10.1.tbz2 HTTP/1.1..Host: m..Accept-Encoding: identity..Range: bytes=-3000..

which does look a little messed. theres a space between gtk and -. the package is actually gtk+-. 

presumably this line in DirHandler#send_dir_listing is causing it:

             child = HttpRequest.unescape(child)

maybe it should only unescape this for the displayed version? eg within the <a></a>? i havent read over everything to look at the overall escaping strategy, but its what i will do for now, so that it stops mangling the filename..

cheers, C
-------------- next part --------------
--- /a/usr/lib/ruby/gems/1.8/gems/mongrel-	2006-08-07 12:26:22.000000000 -0400
+++ ./handlers.rb	2006-08-07 12:28:01.000000000 -0400
@@ -175,12 +175,9 @@
           Dir.entries(dir).each do |child|
             child = HttpRequest.unescape(child)
             next if child == "."
-            if child == ".."
-              out << "<a href=\"#{base}/#{child}\">Up to parent..</a><br/>"
-            else
-              out << "<a href=\"#{base}/#{child}/\">#{child}</a><br/>"
-            end
+            out << "<a href=\"#{base}/#{child}\">"
+            out << (child == ".." ? "Up to parent.." : child)
+            out << "</a><br/>"
           out << "</body></html>"

More information about the Mongrel-users mailing list