Apache -> malformed header from script

Hi all,

I'm on windows xp trying, playing with Ruby on Apache. I've put this
in httpd.conf:

AddHandler cgi-script .rb

And this in index.rb:

#!ruby

print "HTTP/1.0 200 OK\r\n"
print "Content-type: text/html\r\n\r\n"
print "<html><body>Hello World!</body></html>\r\n"

This comes up as a 500 error, with this in the log file:

malformed header from script. Bad header=HTTP/1.0 200 OK: index.rb

Any idea what I'm missing?

Thanks,
Douglas

Douglas Livingstone wrote:

Hi all,

I'm on windows xp trying, playing with Ruby on Apache. I've put this
in httpd.conf:

AddHandler cgi-script .rb

And this in index.rb:

#!ruby

print "HTTP/1.0 200 OK\r\n"
print "Content-type: text/html\r\n\r\n"
print "<html><body>Hello World!</body></html>\r\n"

This comes up as a 500 error, with this in the log file:

malformed header from script. Bad header=HTTP/1.0 200 OK: index.rb

Any idea what I'm missing?

Try just "\n" instead of "\r\n". Since you're on Windows, I think Ruby will output "\r\n" when you use "\n". You may be sending too many newlines.

(I've also just used "\n" on Unix for this kind of thing before, and it always worked fine.)

Jim

···

--
Jim Menard, jimm@io.com, http://www.io.com/~jimm

Hi all,

Hi!

print "HTTP/1.0 200 OK\r\n"

This seems to be your Problem, Apache writes the status line by itself,
it doesn't have the <name>: <value> format like the other header lines.

Hope this helps.

Chris

···

Am Samstag, den 29.01.2005, 03:34 +0900 schrieb Douglas Livingstone:

Try just "\n" instead of "\r\n". Since you're on Windows, I think Ruby will
output "\r\n" when you use "\n". You may be sending too many newlines.

No joy, but, I have solved it! The working code is:

#!ruby

print "Content-type: text/html\n\n"
print "<html><body>Hello World!</body></html>\n"

Turns out ruby or apache or something else is sending the 200 for me,
which is nice :slight_smile: (though I wonder how to change it then... hmm... back
to google...)

All that is needed is

print "\n\n"

to get output, though need the text/html for html naturally :slight_smile:

Thanks,
Douglas

puts <<-EOS
Status: 302
Content-type: text/html

<html>
  <body>
    <p>Hello World!</p>
  </body>
</html>
EOS

-austin

···

On Sat, 29 Jan 2005 05:33:29 +0900, Douglas Livingstone <rampant@gmail.com> wrote:

> Try just "\n" instead of "\r\n". Since you're on Windows, I think Ruby will
> output "\r\n" when you use "\n". You may be sending too many newlines.

No joy, but, I have solved it! The working code is:

#!ruby

print "Content-type: text/html\n\n"
print "<html><body>Hello World!</body></html>\n"

Turns out ruby or apache or something else is sending the 200 for me,
which is nice :slight_smile: (though I wonder how to change it then... hmm... back
to google...)

--
Austin Ziegler * halostatue@gmail.com
               * Alternate: austin@halostatue.ca

Hehe. You send Status: 200 for setting the status line; you have to
tell Apache that it's an "NPH" CGI if you want to send the HTTP line
yourself.

Also, you use just \n, not \r\n, because you're speaking CGI, not
HTTP. The CGI spec declares that \n is the line ending for headers,
and the web server does the translation.

···

On Sat, 29 Jan 2005 05:33:29 +0900, Douglas Livingstone <rampant@gmail.com> wrote:

> Try just "\n" instead of "\r\n". Since you're on Windows, I think Ruby will
> output "\r\n" when you use "\n". You may be sending too many newlines.

No joy, but, I have solved it! The working code is:

#!ruby

print "Content-type: text/html\n\n"
print "<html><body>Hello World!</body></html>\n"

Turns out ruby or apache or something else is sending the 200 for me,
which is nice :slight_smile: (though I wonder how to change it then... hmm... back
to google...)

All that is needed is

print "\n\n"

to get output, though need the text/html for html naturally :slight_smile: