# Ruby Cgi Puzzle on Apache

**URL:** <https://www.ruby-forum.com/t/ruby-cgi-puzzle-on-apache/75224>\
**Category:** Ruby\
**Created:** [November 8, 2006, 10:20am UTC](https://www.ruby-forum.com/t/ruby-cgi-puzzle-on-apache/75224 "2006-11-08T10:20:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![shiwei\_zhang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/eb8c5e/32.png) [@shiwei\_zhang](https://www.ruby-forum.com/u/shiwei_zhang)\
**Post date:** [November 8, 2006, 10:20am UTC](https://www.ruby-forum.com/t/ruby-cgi-puzzle-on-apache/75224/1 "2006-11-08T10:20:18Z")

</div>

Hi, All,

```
     On my Linux machine, I configured Mod_fcgid.2.0 in Apache2.2.3. 

```

And  
I also installed ruby-1.8.5. Then I wrote two .rb files in the Apache  
cgi-bin directory, as follows.  
//////////////////////cgitest01.rb starts/////////////////////  
#!/usr/local/bin/ruby  
puts “”;  
puts “nice prog!”;  
//////////////////////cgitest01.rb ends//////////////////////  
//////////////////////cgitest02.rb starts/////////////////////  
#!/usr/local/bin/ruby  
puts “nice prog!”;  
//////////////////////cgitest02.rb ends/////////////////////  
At this moment I visited  
[http://xx.yyy.com/cgi-bin/cgitest01.rb](http://xx.yyy.com/cgi-bin/cgitest01.rb),  
and it worked well. It printed out “nice prog!” normally.  
However, when I visited  
[http://ts.cn.oracle.com/cgi-bin/cgitest02.rb](http://ts.cn.oracle.com/cgi-bin/cgitest02.rb), I got the following error:  
[Wed Nov 08 17:18:26 2006] [error] [client 146.56.236.149] malformed  
header  
from script. Bad header=nice prog!: cgitest02.rb

Anybody can tell me why I encountered the error when visiting  
cgitest02.rb?  
Why must I put out an empty line (puts “”😉 at the biginning of the file  
if  
I want to successfully visit it?

Many Thanks in advance!

Rgds,  
Shiwei

---

<div class="post-metadata">

**Author:** ![shiwei\_zhang](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/eb8c5e/32.png) [@shiwei\_zhang](https://www.ruby-forum.com/u/shiwei_zhang)\
**Post date:** [November 9, 2006, 12:10am UTC](https://www.ruby-forum.com/t/ruby-cgi-puzzle-on-apache/75224/2 "2006-11-09T00:10:55Z")

</div>

shiwei zhang wrote:

> //////////////////////cgitest02.rb starts/////////////////////  
> Anybody can tell me why I encountered the error when visiting cgitest02.rb?  
> Why must I put out an empty line (puts “”😉 at the biginning of the file if  
> I want to successfully visit it?
> 
> Many Thanks in advance!
> 
> Rgds,  
> Shiwei

You Have To Because That’s How HTTP Works.

Read up on the format of HTTP requests and replies, it will do you a  
load of good. For the abridged version, a HTTP request or reply consist  
of a sequence of headers, one per line (AFAIK), a blank line, and the  
body.

The blank line is part of the HTTP syntax which indicates that headers  
end. (And for a GET request, that the request ends.)

David V.
