Why does basic cgi example fail on Apache/Windows?

This has come up in the past, but why does this bare-bones cgi example (from
Pickaxe) fail on Apache/Windows?

#!c:/ruby/bin/ruby.exe
print "HTTP/1.0 200 OK\r\n"
print "Content-type: text/html\r\n\r\n"
print “Hello World!\r\n”

Error log says:
malformed header from script. Bad header=HTTP/1.0 200 OK: test.rb

Anything using ‘cgi’ works, what is it doing to comfort Apache that the
above does not do? A packet sniff of what comes out of a successful .rb
script using the ‘cgi’ module shows this header:

HTTP/1.1 200 OK
Server: Apache/1.3.14 (Win32)
Content-Length: 1120
Keep-Alive: timeout=15, max=100
Connection: Keep-Alive
Content-Type: text/html

End of lines are OD OA (\r\n), same as above.

Tried Apache 2.0.44 and Apache 1.3.14 running on Windows 2k, both don’t like
the test.rb header (although that same header works fine on IIS…)

Chris
http://clabs.org

···

Date: Wed, 19 Mar 2003 14:34:06 GMT

print "HTTP/1.0 200 OK\r\n"

Don't send this line.

print "Content-type: text/html\r\n\r\n"
print "<html><body>Hello World!</body></html>\r\n"

Error log says:
malformed header from script. Bad header=HTTP/1.0 200 OK: test.rb

                                            ^^^^^^^^^^^^^^^

This line must be send only if the script is an NPH (non-parse-header)
script

The server will generate the appropriate lines when it will receive
"Content-type: text/html"

Guy Decoux

print “HTTP/1.0 200 OK\r\n”

Don’t send this line.

Does this mean the example in Pickaxe should be changed, or is this only an
issue with Apache on Windows?

print "HTTP/1.0 200 OK\r\n"

Don't send this line.

Does this mean the example in Pickaxe should be changed, or is this only an
issue with Apache on Windows?

No, not fatally :-))

If you look at the page 145, no where you find the name of the script, and
your problem was precisely with the name.

The error message was

malformed header from script. Bad header=HTTP/1.0 200 OK: test.rb

                                                             ^^^^^^^

`test.rb' is a "normal" cgi script and it can't send the header line
HTTP/1.0

Now rename it to `nph-test.rb' and it become an nph-script : it can send
this header line, and it will work :-)))

Guy Decoux

We really should change the example (in fact an erratum was added last
year for this).

Cheers

Dave

···

On Wednesday, Mar 19, 2003, at 10:17 US/Central, Chris Morris wrote:

print “HTTP/1.0 200 OK\r\n”

Don’t send this line.

Does this mean the example in Pickaxe should be changed, or is this
only an
issue with Apache on Windows?