The AOLserver automatically generates some HTTP header information and your program can add other information to the header.
HTTP/1.0 200 OK MIME-Version: 1.0 Server: AOLserver/2.1 Date: Monday, 06-Nov-95 17:50:15 GMT Content-length: 20134
However, if the name of your CGI program begins with "nph-
", the AOLserver will not parse the output you send. Instead, the output is sent directly to the client. In this case, you must include the information above in your output. Generally, it is best to avoid using this "non-parsed header" feature because any errors may be sent to standard output and could make the header information incorrect. Also, with non-parsed headers, the server does not interpret the output, so the response code and content length are written out as 0 (zero) and 0 (zero) in the access log file.
Content-type: text/html <HTML> <HEAD><TITLE>My title</TITLE></HEAD> <BODY>text goes here...</BODY> </HTML>
Content-type:
You should always use this header to specify the MIME type of the output you are sending (unless you are using the Location header). If you are sending an HTML page as output, use a Content-type of text/html
. If you are sending untagged text, send a Content-type of text/plain
. If you send images, you might use a Content-type of image/gif
or image/jpeg
. You can send any type of output from your CGI program -- just be sure to specify the correct MIME type.
Example: Content-type: text/html
Content-encoding:
Use this header if the output you are sending is compressed. The Content-type should specify the type of the uncompressed file. For example, use x-gzip
for GNU zip compression and x-compress
for standard UNIX compression.
Example: Content-encoding: x-compress
Expires:
Use this header to specify when the browser should consider the file "out-of-date". Browsers can use this date to determine whether to load the page from their local cache of pages or to reload the file from the server.
Example: Expires: Monday, 06-Nov-95 17:50:15 GMT
Location:
Use this header if you want to send an existing document as output. The server automatically sends the document you specify to the browser. You will probably want to specify a full URL for the Location. If you specify a complete URL (such as, http://www.mysite.com/out/response.htm
), relative references in that file will be resolved using the information in the URL you specify. If you specify a relative URL (such as /out/response.htm
), references in that file will be resolved using the directory that contains the CGI program.
If you send a Location header, you do not need to send a Content-type header. However, you may want to send HTML-tagged text including a link to the location for browsers that do not support this type of redirection. You can specfy any type of URL as the output location. For example, you can send an FTP, Gopher, or News URL.
Example: Location: http://www.my.org/outbox/accepted.html
Status:
The AOLserver sends a status code to the browser in the first line of every HTTP header. The default status code for success is "200 OK". You can send other status codes by specifying the Status header.
Some browsers may not know how to handle all HTTP status codes, so your program should also send HTML output after the header to describe error situations that occur.
Example: Status: 401 Unauthorized
Content-type: text/html
Then, generate and output the HTML tags and content that make up the page. You can send any HTML tags you would normally use when creating pages.
If you use AOLpress to author pages, you can use Tools Show HTML to display the HTML tags and File Save As to save the tags to a separate file that you edit into your CGI program.
If the file you want to send already exists, you can use the Location header described in the previous section to send that file as output from the CGI program.