Logo address

CGI Programing

目次

2006/08/27 Update

Request Meta-Variables

Pegasus 2.2 supports all request meta-variables described in RFC3875 including "PATH_INFO" and "PATH_TRANSLATED".

Pegasus does not support syntax such as

	http://host/dirpath/foo.cgi/datapath
where "dirpath" is the path to CGI script "foo.cgi", and "datapath" is a data for "foo.cgi". The syntax is an extension of NCSA "cgi-bin":
	http://host/cgi-bin/foo.cgi/datapath
which is the most popular implementation of CGI support.

Meta-variables "PATH_INFO" and "PATH_TRANSLATED" of RFC3875 assumes this syntax. The "PATH_INFO" would be "datapath", and "PATH_TRANSLATED" would be "/doc/datapath" if Pegasus supports this syntax.

The approach has a following defect. Suppose a "script1" is designed for "datapath1", and "script2" for "datapath2. Then the following requests are justifiable.

	http://host/cgi-bin/script1/datapath1
	http://host/cgi-bin/script2/datapath2
However it is unpredictable what happens if someone sends a request such as
	http://host/cgi-bin/script1/datapath2
or
	http://host/cgi-bin/script1/unsupposed_datapath
The connection between "script" and "datapath" is in conscience of HTTP clients. Probably much effort will be required in writing scripts which are free from this problem.

Apache server supports executable texts with a header line "#!... ". The merit is in that data is tightly bound to the script. Therefore we have no ambiguity in "script" combined with "datapath".

However the tightness can be a defect: executable text cannot always answer real-life needs such that all files under some directory are to be processed by a specific script, or all files with some suffix are to be processed by a specific script. You will find some of the example at http://plan9.aichi-u.ac.jp/netlib , http://plan9.bell-labs.com/magic/man2html/ , etc.

Execution handler of Pegasus is a natural extension of executable text of Apache. The desirable concept "data driven" is kept in the extension. The handler is designed to be reliable, flexible and powerful.

Then what is the value "PATH_INFO" and "PATH_TRANSLATED"?

Reconsider execution handler of Pegasus:

# path      mimetype    hctl    execpath arg ...
/netlib/*/index.html text/html 0 /bin/ftp2html
*.http         -         1       $target
*.cgi       text/html    +       $target
*.html      text/html    0       $target
*.tt        text/html    0       /bin/peep $target
You will understand that the script needs only the value of "$target" in processing requests from clients.

Pegasus formally assigns null string to "PATH_INFO" and "PATH_TRANSLATED" if "execpath" is same as "$target"; and assigns "$target" if "execpath" is not same as "$target". The assignment answers to the requirement of RFC3875 in typical and simple cases.

Response headers

Pegasus automatically attaches headers that are required in regular response to the request. They are listed below.
	Content-Type	Content-Encoding	Server	Date	ETag
	Content-Length	Connection	Accept-Ranges	Content-Range
	Last-Modified	Cache-Control
The "Cache-Control" value is set "no-cache" for CGI.

Thus, it is enough for the script to write only special headers: if the header name is absent in regular http headers, then the header is added; if the header name is already present in regular http headers, then the header is replaced* by new one in the script.


* Replacement of the following headers are not yet supported: "Content-Range", "Accept-Ranges", "Last-Modified", "Cache-Control". Some of them should be supported, though.

Of course, the following CGI/1.1 specific headers are supported.

	Status	Location

Look RFC3875 for this topic.

Current Working Directory

If URI is
	http://somehost/somepath/something
then current working directory is as follows:
where "somepath" is a path to a directory.

References