For Development HEAD DRAFTSearch (procedure/syntax/module):

12.98 www.cgi.test - CGI testing

Module: www.cgi.test

This module defines a useful procedures to test CGI script. The test actually runs the named script, with specified environment variable settings, and retrieve the output. Your test procedure then examine whether the output is as expected or not.

Function: cgi-test-environment-ref envvar-name
Function: (setter cgi-test-environment-ref) envvar-name value

{www.cgi.test} The module keeps a table of default values of environment variables with which the cgi script will be run. These procedures allow the programmer to get/set those default values.

Note that you can override these default values and/or pass additional environment variables for each call of cgi script. The following environment variables are set by default.

NameValue
SERVER_SOFTWAREcgitest/1.0
SERVER_NAMElocalhost
GATEWAY_INTERFACECGI/1.1
SERVER_PROTOCOLHTTP/1.1
SERVER_PORT80
REQUEST_METHODGET
REMOTE_HOSTremote
REMOTE_ADDR127.0.0.1
Function: call-with-cgi-script script proc :key (environment ()) (parameters #f)

{www.cgi.test} Runs a script with given environment, and calls proc with one argument, an input port which is connected to the pipe of script’s standard output. The argument script should be a list of program name and its arguments. Each element are passed to x->string first to stringify. The script is run under the environment given by environment variable and the default test environment described above. The environment argument must be an associative list, in which each key (car) is the name of the environment variable and its cdr is the value. Both are passed to x->string first. If the same environment variable appears in environment and the default test environment, the one in environment is used. Additionally, if an associative list is given to the parameters argument, a query string is built from it and passed the script. The actual method to pass the query string depends on the value of REQUEST_METHOD environment variable in the setting. If REQUEST_METHOD is either GET or HEAD, the query string is put in an environment variable QUERY_STRING. If it is POST, the query string is fed to the standard input of the script. In the latter case, CONTENT_TYPE is set to application/x-www-form-urlencoded and CONTENT_LENGTH are set to the length of QUERY_STRING automatically. If REQUEST_METHOD is other values, parameters is ignored. You can bypass this mechanism and set up environment variable QUERY_STRING directly, if you wish.

Function: run-cgi-script->header&body script reader :key environment parameters

{www.cgi.test} A convenient wrapper of call-with-cgi-script. The script, environment and parameters are passed to call-with-cgi-script as they are. The output of the script is parsed by run-cgi-script->header&body. First, the RFC2822 header fields are parsed by rfc822-read-headers (see rfc.822 - RFC822 message parsing). Then, the reader is called with an input port which is piped to the script’s output. Run-cgi-script->header&body returns two values, the list of headers (as parsed by rfc822-read-headers), and the return value of reader.

Function: run-cgi-script->sxml script :key environment parameters

{www.cgi.test} This is a procedure that uses ssax:xml->sxml (see sxml.ssax - Functional XML parser) as the reader in run-cgi-script->header&body. Useful when you’re testing a cgi script that produces well-formed HTML and/or XML document.

Function: run-cgi-script->string script :key environment parameters
Function: run-cgi-script->string-list script :key environment parameters

{www.cgi.test} These procedures use port->string and port->string-list (see Input utility functions) as the reader in run-cgi-script->header&body, respectively.

An example:

(run-cgi-script->string-list "bbs.cgi"
                             :environment '((REMOTE_ADDR . "12.34.56.78"))
                             :parameters '((command . "view")
                                           (page . 1234)))


For Development HEAD DRAFTSearch (procedure/syntax/module):
DRAFT