[cs631apue] Expected output for cgi

Jan Schaumann jschauma at stevens.edu
Tue Nov 17 21:02:50 EST 2015


> As discussed yesterday , please send us the examples which will help us
> understanding the expected output for CGIs.

There is no expected output for CGIs.  When a request is made for a URI
under a CGI directory, then your server will execute the file found in
that location rather than serve its contents.

How the program is executed and what your server should do prior to
executing the program is described in detail in RFC3875, but in very
brief, you'd prepare the environment, connect the I/O fd's
appropriately, and then execute the program.

Your server will generate the basic HTTP response headers (status code,
date, server, last-modified), but let the program generate the headers
it needs to (content-type, content-length, anything else).

If the request was a GET request, then any parameters provided in the
request are added to the environment in the QUERY_STRING variable; if
the request was a POST request, then the data submitted by the client is
fed to the program on stdin.

Some examples of CGIs can be found here:
https://www.cs.stevens.edu/~jschauma/cgi-bin/env.cgi
https://www.cs.stevens.edu/~jschauma/cgi-bin/post.cgi

You can try posting data to post.cgi or adding paramenters to env.cgi to
see how the output changes; you can read the sources of these files on
linux-lab under ~jschauma/public_html/cgi/bin/.

-Jan


More information about the cs631apue mailing list