menu
 
home home home books palm tech web
 

TN110 - CGI Test Cases

 
 
110.1   Summary
110.2   CGI Documentation
110.3   CGI Input Test Cases
110.4   CGI Output Test Cases
 
 

110.1 Summary

The Common Gateway Interface (CGI) is a simple specification for a web server to invoke a program to dynamically generate the contents of a web page. The specification defines how the web server passes data to and from the program that it calls. Although serious web based development now uses application servers, CGI's still have value in simpler applications and as a tool to understand the interaction of web based applications with a web browser.  
 

110.2 CGI Documentation

The CGI specification is a de facto standard that has never been clearly documented by an authoritative body. The following is the best documentation on the subject.

CGI: Common Gateway Interface - The few official words on the CGI specification from the World Wide Web Consortium.

The Common Gateway Interface - The original CGI definition developed by NCSA Software Development Group.

Golux RFC Project Page - The latest version of the Internet draft for a CGI specification. It expired before being accepted as an RFC.

CGI Programming with Perl - The best single source of information is this book from O'Reilly. Although a CGI can be written in any language, perl is a common language and serves to illustrate the concepts easily.

CGI.pm - a Perl5 CGI Library - Lincoln Stein's CGI.pm, the popular perl module used in the vast majority of perl CGI's.

Official Guide to Programming With CGI.pm - By Lincoln Stein, the developer of CGI.pm.

110.3 CGI Input Test Cases

CGIs get input in three ways, via command line arguments, STDIN, and as passed through environment variables.

NCSA originally provided some examples to demonstrate various input cases here. Unfortunately their site seemed to be broken on the day I needed to experiment with it, so I recreated simlar test cases and a CGI to show the input. You can see the source.

In particular, note STDIN, arguments, and environment variables PATH_INFO, and QUERY_STRING.

a. This is just a request for a CGI script with no extra path information and no query.   b. This is a request for a script with extra path information, and no query.
  /tn110/show.cgi
 
    /tn110/show.cgi/foo/bar
 
c. This is a request for a script with no extra path information, and an ISINDEX query.   d. This is a request for a script with no extra path information, and an ISINDEX query with multiple arguments.
  /tn110/show.cgi?foo
 
    /tn110/show.cgi/?foo+bar
 
e. This is a request for a script with no extra path information, and one name=value pair.   f. This is a request for a script with extra path information, and multiple name=value pairs.
  /tn110/show.cgi?foo=1
 
    /tn110/show.cgi/extra/path/?f=1&b=2
 
g. This is a request for a script with extra path information as well as an ISINDEX query.

/tn110/show.cgi/extra/path?foo+bar
 

  h. Clicking the submit button will send a form request with no extra path information using the GET method.

<form action="/tn110/show.cgi" method=" GET">
<input type="checkbox" name="button" value="on">
<input type="submit" name="form_h" value="Example_h">

Check me.

 
i. Clicking the submit button will send an form request with no extra path information using the POST method.

<form action="/tn110/show.cgi" method=" POST">
<input type="checkbox" name="button" value="on">
<input type="submit" name="form i" value="Example i">

Check me.

 
  j. Clicking the submit button will send an form request with extra path information of /foo using the POST method.

<form action="/tn110/exam.cgi/foo" method="POST">
<input type="checkbox" name="button" value="on">
<input type="submit" name="form j" value="Sumbit example j">

Check me.

 
k. Clicking the submit button will send an form request with no extra path information using the POST method and with a multiline text area.
 

  l. Clicking the submit button will send an form request with extra path information of /foo using the POST method, with a multiline text area,a nd with enctype set to multipart/form-data.
 

  <form action="/tn110/show.cgi" method="POST">
<textarea name="foo" cols="20" rows="4"> </textarea>
<input type="submit" name="form k" value="Example i">

 

    <form action="/tn110/exam.cgi/foo" method="POST" enctype="multipart/form-data">
<textarea name="foo" cols="20" rows="4"> </textarea>
<input type="submit" name="form l" value="Submit example j">

 

 

 
   

 

110.4 CGI Output Test Cases

Typically, a CGI provides "parsed headers" terminated by a blank line and then followed by the remaining content (such as HTML) to STDOUT. The specification does not define how web servers should handle output to STDERR. Some web servers will error and some will treat it the same as STDOUT. See CGI Script Output for details of the headers. See case 4(i) for an example of non-parsed headers.

The typical header is Content-type, which is described in the MIME specification in RFC 2045, RFC 2046, RFC 2047, RFC 2048, and RFC 2049. See Media Types for a list of the possible values.

The following test cases demonstrate how different headers change the behavior of the browser. Content-type headers are also transmitted with regular web pages and other files served by a web server. The header transmitted by the web server depends on its configuration and is typically based on the file extention. With a CGI we choose the Content-type header.

  CGI   Headers
a. This CGI returns the header on the right followed by sample HTML
/tn110/text-html.cgi/
View source.
 
  Content-type: text/html
b. This CGI returns the header on the right followed by sample ASCII text.
/tn110/text-plain.cgi/
View source.
 
  Content-type: text/plain
c. This CGI returns the headers on the right with the value of content type set by the ISINDEX query and then followed by the binary file specified in the extra path info. Note that we lie about the content-type in the second case.
/tn110/ctype.cgi/sample.doc?msword
/tn110/ctype.cgi/sample.xls?msword
View source.
 
  Content-type: application/msword
Content-Transfer-Encoding: binary
d. This CGI returns the headers on the right with the value of content type set by the ISINDEX query and then followed by the binary file specified in the extra path info. Note that sample.unk is a valid excel file with the extension changed to "unk."
/tn110/ctype.cgi/sample.xls?vnd.ms-excel
/tn110/ctype.cgi/sample.unk?vnd.ms-excel
View source .
 
  Content-type: application/vnd.ms-excel
Content-Transfer-Encoding: binary
e. This CGI returns the headers on the right followed by the binary file specified in the extra path info
/tn110/bdown.cgi/sample.doc
/tn110/bdown.cgi/sample.unk
/tn110/bdown.cgi/sample.txt
View source .
 
  Content-type: application/octet-stream
Content-Transfer-Encoding: binary
Content-Disposition: attachment; filename=sample.doc
f. This CGI returns just the header on the right with the location value extracted from the extra path info.Note that the ? seperating the qurey is writen in hex as %3F so that the browser will pass is back as part of the extra path.
/tn110/link.cgi/http://www.google.com/ search%3Fq=porsche
View source.
 
  Location: http://www.google.com/ search%3Fq= porsche
g. This CGI returns the header on the right with the expiration set to now + five minutes. A compliant web browser will expire this page from its cache by this time.
/tn110/exp-sample.cgi/
View source.
 
  Content-type: text/plain
Expires: Weekday, dd-mmm-yy HH:MM:SS GMT
h. This CGI returns the headers on the right. /tn110/pra-sample.cgi/
View source.
 
Note - The Cache-Control: no-cache response header tells the client and all intermediary caches not to cache this web page. Unfortunately this header was not defined until HTTP/1.1, so it will not work with a HTTP/1.0 browser. The Pragma: no-cache header was not originally intended to be a response header, but some browsers, under certain conditions treat it like a Cache-Control: no-cache header. It is included only as an attempt to stop caching on HTTP/1.0, but should not be considered reliable. See the HTTP/1.1 specification 14.32 and 14.9 for more details. For a more sophisticated caching test see: Procata Web Caching Tests
 
  Content-type: text/plain
Cache-Control: no-cache
Pragma: no-cache
i. This CGI returns the headers on the right. The nph prefix (non-parsed headers) of the CGI causes the web server to suspend all other headers and not to buffer the output of the CGI.
/tn110/nph-sample.cgi/
View source.
 
  HTTP/1.0 200 OK
Apache/1.3.27 (Unix)
Content-type: text/plain
 
 
 

 
[books]  [palm]  [tech]  [web]  [PGP keys] 
© Copyright 2000. All rights reserved.