[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Apache -> malformed header from script

Douglas Livingstone

1/28/2005 6:35:00 PM

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


5 Answers

Jim Menard

1/28/2005 6:48:00 PM

0

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...



Christian Schorn

1/28/2005 6:52:00 PM

0

Am Samstag, den 29.01.2005, 03:34 +0900 schrieb Douglas Livingstone:
> 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



Douglas Livingstone

1/28/2005 8:33:00 PM

0

> 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

1/28/2005 8:43:00 PM

0

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 :) (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 * halostatue@gmail.com
* Alternate: austin@halostatue.ca


Aredridel

1/29/2005 7:52:00 PM

0

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