Discussion:
Apache -> malformed header from script
Douglas Livingstone
2005-01-28 18:34:31 UTC
Permalink
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
Jim Menard
2005-01-28 18:48:20 UTC
Permalink
Post by Douglas Livingstone
Hi all,
I'm on windows xp trying, playing with Ruby on Apache. I've put this
AddHandler cgi-script .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"
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, ***@io.com, http://www.io.com/~jimm
Douglas Livingstone
2005-01-28 20:33:29 UTC
Permalink
Post by Jim Menard
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
Austin Ziegler
2005-01-28 20:43:27 UTC
Permalink
On Sat, 29 Jan 2005 05:33:29 +0900, Douglas Livingstone
Post by Douglas Livingstone
Post by Jim Menard
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.
#!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
--
Austin Ziegler * ***@gmail.com
* Alternate: ***@halostatue.ca
Aredridel
2005-01-29 19:52:16 UTC
Permalink
On Sat, 29 Jan 2005 05:33:29 +0900, Douglas Livingstone
Post by Douglas Livingstone
Post by Jim Menard
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.
#!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.

Christian Schorn
2005-01-28 18:51:48 UTC
Permalink
Post by Douglas Livingstone
Hi all,
Hi!
Post by Douglas Livingstone
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
Continue reading on narkive:
Search results for 'Apache -> malformed header from script' (Questions and Answers)
3
replies
Where can I find this shirt online?
started 2009-03-09 15:12:51 UTC
fashion & accessories
Loading...