From: Simon Strandgaard Date: 2004-11-30T16:20:00+09:00 Subject: Re: WEBrick HTTPRequest#to_s should never fail, but does On Tue, 30 Nov 2004 08:12:29 +0900, GOTOU Yuuzou wrote: > In message , > `Simon Strandgaard ' wrote: > > What is your opinion on the policy for #to_s, do you think its good or > > bad that it fails ? > > I think it's unavoidable for the incorrect messages. > Of course it should be fixed if it's a bug. Ok, I should have told you that im dealing want to deal with incorrect messages. Konqueror 3.3.1's XMLHttpRequest sends a "Context-Length: xyz\n\n" in the body, instead of the header. On the server I correct the message before processing it. It was difficult to get working because I couldn't inspect the contents of the broken request. You can read more about this problem, here: http://lists.kde.org/?l=kfm-devel&m=110139670817086&w=2 I do something ala this: if req["user-agent"] =~ /Konqueror\/3.3/ puts "Workaround for Konqueror/3.3" # Konqueror 3.3.1 sends a response with two extra lines.. # containing "Content-Length: 12345\n\n" # This code gets rid of them socket = req.instance_variable_get("@socket") removed = req.send(:read_line, socket) removed += req.send(:read_line, socket) m = removed.match(/\AContent-Length: (\d+)/) unless m raise WEBrick::HTTPStatus::Forbidden, "Konqueror/3.3 workaround failed, wrong content-length syntax" end cl = m[1] puts "content-length=#{cl} removed=#{removed.inspect}" unless req.header raise WEBrick::HTTPStatus::Forbidden, "Konqueror/3.3 workaround failed, no header" end req.header["content-length"] = [cl] end Even though this is a bit dirty, I still think that #to_s should never fail. Sorry for this, Thanks for WEBrick. -- Simon Strandgaard