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

<html>
<head>

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:

1. I can't work out how the results of calling @cgi.header(@headers) in
rails actually gets turned into a real HTTP response
2. 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



Sam Joseph wrote:

>Hi there,
>
>I can't tell if this is a problem with the ruby cgi library or with
>rails action pack (no response from the rails list so far), but I get an
>occasional error in the http headers from rails like this:
>
>HTTP/1.x 200 OK
>Date: Thu, 02 Feb 2006 20:56:03 GMT
>Server: Apache/2.0.54 (Debian GNU/Linux) PHP/4.3.10-16 mod_ruby/1.2.4
>Ruby/1.8.4(2005-12-24)
>#<#<Class: 0x40b8e99c>:0x40b8e8d4>Content-Type: text/html
>Cache-Control: no-cache
>
>Some kind of object data is getting dumped in front of the Content-Type,
>which screws up how some browsers display the page.
>
>Setting Content-Type explicitly in the controller doesn't seem to help,
>and so far I have been unable to detect what causes this, or why it
>happens under some circumstances and not others - I am posting this here
>in case anybody has seen something similar, or has ideas about possible
>causes.
>
>Many thanks
>
>CHEERS> SAM
>
>
>
>
>  
>