CGI Scripts


BRS WebWeaver partially implements the CGI/1.1 specification. CGI enables HTTP server to be extended via server-side applications. Stdin, stdout and environment variables are used to communicate between the HTTP Server and the CGI application.

BRS WebWeaver uses operating system pipes to stream data between the CGI process and the server without requiring intermediate buffering.  Currently the stdin pipe is not connected, so that CGI processes can not read from the server, it can only write to stdout.

CGI Directories
All scripts found in the CGI directory should be executable applications with the exception of documents of type: .txt .htm or .html. These document types are recognized as text and are not executed, however, all other document types should be served out of the Documents Directory.

Currently BRS WebWeaver only allows CGI applications to be served out of the directory specified in the CGI Directory variable.  Also, currently only applications with extentions of .exe and .bat are recognized and properly executed by BRS WebWeaver.

CGI Directory Location
By default the CGI directory is a directory called scripts that is located under the installation directory for BRS WebWeaver.


Environment Variable Description
SERVER_SOFTWARE is the current name and version BRS WebWeaver responding to the request.
SERVER_NAME is the server's hostname, DNS alias, or IP address as it would appear in self-referencing URLs.
GATEWAY_INTERFACE is the revision of the CGI sepcification to which the server complies.  (currently only CGI/1.1 for CGI apps)
SERVER_PROTOCOL is the name and revision of the protocol this request came in with.  (currently only HTTP/1.0)
SERVER_PORT specifies port to which the request was sent.
REQUEST_METHOD is the method with which the request was made: "GET", "POST" etc. (currenlty only GET)
QUERY_STRING is defined as anything following the first '?' in the URL. Typically this data is the encoded results from your GET form. The string is encoded in the standard URL format changing spaces to +, and encoding special characters with %xx hexadecimal encoding.
PATH_INFO The extra path information, as given by the client.
PATH_TRANSLATED The server provides a translated version of PATH_INFO, which takes the path and does a virtual-to-physical maping to it.
SCRIPT_NAME is a virtual path to the script being executed.
REMOTE_HOST is the host name making the request. If DNS lookup is turned off, the REMOTE_ADDR is set and this variable is unset.
REMOTE_ADDR is IP address of the remote host making the request.
CONTENT_LENGTH is length of any attached information from an HTTP POST. (currently not used)
CONTENT_TYPE is the media type of the posted data (usually application/x-www-form-urlencoded).
Returning Data CGI programs can return content in many different document types (i.e. text, images, audio). They can also return references to other documents. To tell the server what kind of document you are sending back, CGI requires you to place a short header on your output. This header is ASCII text, consisting of lines separated by either linefeeds or carriage returns (or both) followed by a single blank line. The output body then follows in whatever native format.

If you begin your script output with  "HTTP/" then the BRS WebWeaver will send all output exactly as the script has written it to the client. Otherwise, the Sambar Server will send a default header back (text/html file type) with any data returned from the script.

For example, to send back HTML to the client, your output should read:

        Content-type: text/html

        <HTML><HEAD>
        <TITLE>output of HTML from CGI script</TITLE>
        </HEAD><BODY>
        <H1>Sample output</H1>
        Blah, blah, blah.
        </BODY></HTML>


In the above example, the response prepended is: HTTP/1.0 200 OK
To reference a file on another HTTP server, you would output something like this:
        Location: http://www.sambar.com/
        Content-type: text/html

        <HTML><HEAD>
        <TITLE>Whoops...it moved</TITLE>
        </HEAD><BODY>
        <H1>Content Moved!</H1>
        </BODY></HTML>
In the above example, the response prepended is: HTTP/1.0 302 MOVED

© 1999 Blaine R Southam. All rights reserved. Terms of Use.