James H. Zisch - Computer Services

Support : Guides

 

CGI Output

Typically, when sending output from a program you are either writing to a data file, or sending the output to a device or subsystem. With web CGI modules the output intended for the web browser is directed to the web server subsystem via STDOUT (Standard Out). The web CGI can also read and write to data files on the server and to other devices, but the conclusion of the process must send output back to the web browser that invoked it to satisfy the invocation request.

In addition to sending the output there is other information that can be sent pertaining to the data. This additional information includes "PRAGMA" statements to control the caching of the item, expiration of the item, cookies, and other information.

Effectively, the web server listens to the STDOUT stream of the web CGI module and if it detects a "signal" that what's coming next is to be sent to the requesting web browser, then the web server passes the information along to the IP address of the requestor. The signal also specifies what type of data is to be sent instructing the web server as to how to package the data as well as telling the requestor's web browser or application how to interpret the data returned. Output can be in text or binary data format. This means the web CGI module can send web pages, data files, graphic image files, program files, etc. as a response to the request.

An example of the "signal" to begin transmission of an HTML page would be:

print "Content-type: text/html","\n\n";

Other MIME type can be specified as well. An example of the "signal" to begin transmission of an GIF image would be:

print "Content-type: image/gif","\n\n";

Another signal that can be sent is a "Location" causing the resource at that location to be returned to the requestor as opposed to returning content. An example of a "Location" signal is:

print "Location: http://www.jhz-cs.com/index.html","\n\n";

And, instead of returning either content or a location, a web CGI module may instead return only a "Status" code. An example of a "Status" signal indicating the resource requested is not found would look like this:

print "Status: 404 Not Found","\n\n";