Just ran into a problem[1]. It seems to have been introduced by changeset 224 [2], a fix for ticket 126 [3]. The root is the number of CRLFs Camping puts between the headers and the body of the response. This has changed at least 3 times; right now we''re back to 1. (ie. every header ends in a CRLF, and then there''s the body) The HTTP RFC[4], the CGI spec[5] and the FastCGI FAQ[6] all seem to agree that there should be 2 (ie. every header ends in a CRLF, then there''s another CRLF, then there''s the body). (AFAIK looking for the first CRLFCRLF is the only reliable way to tell where the headers end and the body begins). There''s clearly a bug here, but whether it''s with CGI on Apache or FastCGI on lighttpd or Camping''s handling of one or the other, I can''t say. Can anybody shed some light on the situation? [1]: <http://code.whytheluckystiff.net/camping/ticket/147> [2]: <http://code.whytheluckystiff.net/camping/changeset/224> [3]: <http://code.whytheluckystiff.net/camping/ticket/126> [4]: <http://www.apps.ietf.org/rfc/rfc2616.html#sec-6> [5]: <http://hoohoo.ncsa.uiuc.edu/cgi/out.html> [6]: <http://www.fastcgi.com/docs/faq.html#incomplete_headers> -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://rubyforge.org/pipermail/camping-list/attachments/20071122/61c7dbb9/attachment-0001.bin
I guess I should have waited a bit longer to send that email, I think I''ve tracked it down. When one of the values in @headers contains an empty list we get a superfluous CRLF, ie:>> Z = "\r\n">> headers = {"Content-Type"=>"text/plain;charset=utf-8", "Set-Cookie"=>[]} >> headers.map{|k,v|[*v].map{|x|[k,v]*": "}}*Z+Z # the relevant part of Base#to_s=> "Content-Type: text/plain;charset=utf-8\r\n\r\n" ...>> headers["Set-Cookie"] = "something" >> headers.map{|k,v|[*v].map{|x|[k,v]*": "}}*Z+Z=> "Content-Type: text/plain;charset=utf-8\r\nSet-Cookie: something\r\n" If no cookies have been set, @headers["Set-Cookie"] = [] and you get the correct number of CRLFs; otherwise, you''re short one. I''ll leave it to the golfing pros to figure out the best fix for that. Unfortunately this brings another, unrelated problem to my attention; apparently I''m getting "0x1df\r\n" inserted between my headers and my body. Only on FastCGI, and only with Camping. Maybe it''s time to move from FastCGI :(. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 189 bytes Desc: not available Url : http://rubyforge.org/pipermail/camping-list/attachments/20071122/b59527f5/attachment.bin
Hey Brendan, thanks a lot for your insightful investigation. I''ve committed the fix [239], I hope it solves the problem now :) A propos FastCGI, I think that Camping should drop it''s support. I don''t know what other people think, but if you look at the bug tracker, most bugs are related to it. Since Rack has a camping handler, for those people who really need fastcgi, they could get it trough it. -- Cheers, zimbatm