carmen
2006-Aug-07 17:03 UTC
[Mongrel] DirHandler in surplus slashing / unrequited unescaping
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 (24.66.193.83): Invalid HTTP format,
parsing fails.
in ngrep port 80, the last request is this:
T 24.69.123.83:39560 -> 24.91.155.55:80 [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-0.3.13.3/lib/mongrel/handlers.rb
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/>"
end
out << "</body></html>"
end
Zed Shaw
2006-Aug-07 18:12 UTC
[Mongrel] DirHandler in surplus slashing / unrequited unescaping
On Mon, 2006-08-07 at 17:03 +0000, carmen wrote:> 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: >Yep, but good timing because I''m working on the DirHandler right now.> 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.. >Yeah, that was to get around how people don''t add trailing slashes. I''m working up a fix that instead redirects to the / version, but haven''t worked out the logic yet. I applied your patch and it all seems to work. Grab the latest pre-releases at: sudo gem install mongrel --source=http://mongrel.rubyforge.org/releases/> 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 (24.66.193.83): Invalid HTTP format, parsing fails. > > in ngrep port 80, the last request is this: > > T 24.69.123.83:39560 -> 24.91.155.55:80 [AP] > GET /files/usr/portage/packages/All//gtk -2.10.1.tbz2 HTTP/1.1..Host: m..Accept-Encoding: identity..Range: bytes=-3000.. > ..<snip>> 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..Hmm, that''s probably right. I''ll put it in my list of bugs to fix, but feel free to work up a patch since you''re probably the most advanced DirHandler user right now. -- Zed A. Shaw http://www.zedshaw.com/ http://mongrel.rubyforge.org/ http://www.railsmachine.com/ -- Need Mongrel support?