this is a problem that's been driving me nuts ever since i first tried it.
i can create simple, minimal scripts in Python, Perl, and PHP that run
flawlessly on the first try with minimal effort, both on my local testing
system (Apache 2.0.52 and Ruby 1.8.2) and on the server my personal site is
hosted on (Apache 1.3.33 and unknown version of Ruby - i'm trying to find
out). but no matter what i try, i simply can not get even the most minimal
ruby script to function:
#!/usr/bin/env ruby
print "Content-type: text/html\n\n"
print "<html><body>Hello World!</body></html>\n"
it runs perfectly fine at the console, no warnings, no errors, no problems.
but as a CGI script, it's another story: i get an error 500 and the cryptic
(and seemingly common) "Premature end of script headers". no other warnings
or errors. if i simply change "ruby" to "python" on the shebang line, the
above script magically works with no other effort on my part.
nothing magic about it:
[ahoward@localhost ~]$ cat a.rb
#!/usr/bin/env ruby
print "Content-type: text/html\n\n"
print "<html><body>Hello World!</body></html>\n"
[ahoward@localhost ~]$ cat a.py
#!/usr/bin/env python
print "Content-type: text/html\n\n"
print "<html><body>Hello World!</body></html>\n"
[ahoward@localhost ~]$ a.rb | od -c > a.rb.out
[ahoward@localhost ~]$ a.py | od -c > a.py.out
[ahoward@localhost ~]$ diff -u a.rb.out a.py.out
--- a.rb.out 2005-05-21 17:58:33.000000000 -0600
+++ a.py.out 2005-05-21 17:58:35.000000000 -0600
@@ -1,5 +1,6 @@
0000000 C o n t e n t - t y p e : t e
-0000020 x t / h t m l \n \n < h t m l > <
-0000040 b o d y > H e l l o W o r l d
-0000060 ! < / b o d y > < / h t m l > \n
-0000100
+0000020 x t / h t m l \n \n \n < h t m l >
+0000040 < b o d y > H e l l o W o r l
+0000060 d ! < / b o d y > < / h t m l >
+0000100 \n \n
+0000102
or, put another way:
harp:~ > ruby -e 'print 42' | od -c
0000000 4 2
0000002
harp:~ > python -c 'print 42' | od -c
0000000 4 2 \n
0000003
so you were just lucky that python and perl were sending you 'extra' newline.
you'd have even more issues if you did something like on a unix vs windows box
and it's the reason cgi abstraction are made.
this will work no matter what platform:
[ahoward@localhost ~]$ cat a.rb
#!/usr/bin/env ruby
require 'cgi'
CGI::new.out{ "<html><body>Hello World!</body></html>\n" }
[ahoward@localhost ~]$ ruby a.rb < /dev/null
Content-Type: text/html
Content-Length: 39
<html><body>Hello World!</body></html>
[ahoward@localhost ~]$ ruby a.rb < /dev/null | od -c
0000000 C o n t e n t - T y p e : t e
0000020 x t / h t m l \r \n C o n t e n t
0000040 - L e n g t h : 3 9 \r \n \r \n <
0000060 h t m l > < b o d y > H e l l o
0000100 W o r l d ! < / b o d y > < /
0000120 h t m l > \n
0000126
you'll also note that cgis are supposed to send '\r\n' not '\n\n' so the other
two never really should have worked anyhow 
i'm going insane because nothing, AFAICT, is wrong. the server is correctly
set-up, permissions are correct, ownership is correct, ruby is installed and
working, yet NOTHING seems to coax it into working. it repeatedly reports
this incredibly uninformative "Premature end of script headers" error.
this is because the script headers prematurely ended before the content started
since \r\n was never seen 
is there something i could have missed? a possible misconfiguration? or
does ruby just hate me?
doubtful 
-a
···
On Sun, 22 May 2005, greyfade@gmail.com wrote:
--
email :: ara [dot] t [dot] howard [at] noaa [dot] gov
phone :: 303.497.6469
My religion is very simple. My religion is kindness.
--Tenzin Gyatso
===============================================================================