CGI Script Output


Script output

The script sends its output to stdout. This output can either be a document generated by the script, or instructions to the server for retrieving the desired output.


Script naming conventions

Normally, scripts produce output which is interpreted and sent back to the client. An advantage of this is that the scripts do not need to send a full HTTP/1.0 header for every request.

Some scripts may want to avoid the extra overhead of the server parsing their output, and talk directly to the client. In order to distinguish these scripts from the other scripts, CGI requires that the script name begins with nph- if a script does not want the server to parse its header. In this case, it is the script's responsibility to return a valid HTTP/1.0 (or HTTP/0.9) response to the client.


Parsed headers

The output of scripts begins with a small header. This header consists of text lines, in the same format as an HTTP header, terminated by a blank line (a line with only a linefeed or CR/LF). Currently, this specification defines two valid (and mutually exclusive) directives for these lines.


Examples

Let's say I have a fromgratz to HTML convertor. When my convertor is finished with its work, it will output the following on stdout (note that the lines beginning and ending with --- are just for illustration and would not be output):

--- start of output ---
Content-type: text/html

--- end of output ---
Note the blank line after Content-type.

Now, let's say I have a script which, in certain instances, wants to return the document /path/doc.txt from this server just as if the user had actually requested http://server:port/path/doc.txt to begin with. In this case, the script would output:

--- start of output ---
Location: /path/doc.txt

--- end of output ---
The server would then perform the request and send it to the client.

Let's say that I have a script which wants to reference our gopher server. In this case, if the script wanted to refer the user to gopher://gopher.ncsa.uiuc.edu/, it would output:

--- start of output ---
Location: gopher://gopher.ncsa.uiuc.edu/

--- end of output ---
Finally, I have a script which wants to talk to the client directly. In this case, if the script is referenced with SERVER_PROTOCOL of HTTP/1.0, the script would output the following HTTP/1.0 response:

--- start of output ---
HTTP/1.0 200 OK
Server: NCSA/1.0a6
Content-type: text/plain

This is a plaintext document generated on the fly just for you.

--- end of output ---

Return to the interface specification

Rob McCool robm@ncsa.uiuc.edu