Hi,
So more information on the header corruption.
I tried adding a slice! instruction to remove the offending part of the
http headers. Rails ActionController::CgiResponse normally uses the
following:
output.write(@cgi.header(@headers))
which I replaced with:
headers = @cgi.header(@headers)
headers.slice!(/#<#<(C|c)lass: 0x[\w\d]>:0x[\w\d]>/)
output.write(headers)
testing that my regex really did match the offending string.
However, this addition did not remove the offending string, and writing
the headers out into the body of the response gave me this
Content-Type: text/html
Set-Cookie: _session_id=936ba003910da551a472708d4b7b3ff3; path=/
Status: 200 OK
Cache-Control: no-cache
suggesting to me that the problem was being introduced at a different
stage … However, superficially I cannot work out how this set of
headers is actually transformed into the headers we see in the HTTP
header itself which looks like this:
HTTP/1.x 200 OK
Date: Tue, 07 Feb 2006 13:59:08 GMT
Server: Apache/2.0.54 (Debian GNU/Linux) PHP/4.3.10-16
#<#<Class: 0x40bdaff4>:0x40bdaf2c>Content-Type: text/html
Cache-Control: no-cache
Set-Cookie: _session_id=936ba003910da551a472708d4b7b3ff3; path=/
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Transfer-Encoding: chunked
Content-Type: text/plain
The implication being that the header string is transformed somewhere
that I have been unable to determine.
I’ve even checked by dumping the @cgi, @headers and ENV objects as YAML
into the HTML body, and then reassembling them locally. As far as I can
tell, within rails, the operation:
@cgi.header(@headers)
generates a string like:
Content-Type: text/html
Set-Cookie: _session_id=936ba003910da551a472708d4b7b3ff3; path=/
Status: 200 OK
Cache-Control: no-cache
but the output from rails through Apache is a properly formed HTTP
header.
From looking at the ruby cgi library, I can see that if I was using
mod_ruby that the output would be different, and would be directed
straight to Apache, but I’m not using mod_ruby, so now I have two
problems:
- I can’t work out how the results of calling @cgi.header(@headers) in
rails actually gets turned into a real HTTP response
- I still can’t see where this strange string is being introduced
I have discovered a work around that is a bit of a hack, but I will post
the patch to the rails ticket I have opened:
http://dev.rubyonrails.org/ticket/3703
I’d still like to work out what causes this problem so I can properly be
rid of it.
Another very weird thing is that I appear to be able to comment out the
contents of the process_cgi method in actioncontrollers cgi_process.rb,
but that things still keep functioning - other changes in the same file
have effects on the http output, just not for the process_cgi method,
which is the only place I can see in the code where the CgiResponse out
method gets called. Clearly I’m still missing a big chunk of this
puzzle.
CHEERS> SAM