From: "greyfade@..." Date: 2005-05-23T16:40:16+09:00 Subject: Re: Ruby and CGI error 500 Ara.T.Howard wrote: > On Sun, 22 May 2005, greyfade@gmail.com wrote: > > > 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 "Hello World!\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: > would it have been better if i'd said "works as expected" or "begins working as expected" instead of "magically"? you seem to have missed everything else in my post. > 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. > irrelevant. running the script locally at a console produces the expected result: ruby gives two newlines (resulting in one blank line) after the Content-Type header and Python gives three newlines (resulting in two). by my understanding, the extra newline in python *SHOULDN'T* work. > > 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 ;-) > irregardless, they *DID*. so stop nitpicking and telling me things i already know. > > 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 ;-) > not true. the script works in Python and Perl perfectly without "\r\n". if that's out of spec, so be it. i'll be sure to obsrve the spec in the future and use "\r\n" from now on. but writing a script to produce *identical* output compared to the ruby script in other programming languages WORKS FINE in CGI. _RUBY_DOES_NOT_ and this is the issue i've come asking for help on. your nitpicking on irrelevant details does not help to further anything.