Apache -> malformed header from script

  • Thread starter Douglas Livingstone
  • Start date
D

Douglas Livingstone

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
 
J

Jim Menard

Douglas said:
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
 
D

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 :) (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 :)

Thanks,
Douglas
 
A

Austin Ziegler

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 :) (though I wonder how to change it then... hmm... back
to google...)

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

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

-austin
 
A

Aredridel

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 :) (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 :)

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top