Next: www.css
- CSS parsing and construction, Previous: www.cgi
- CGI utility, Up: Library modules - Utilities [Contents][Index]
www.cgi.test
- CGI testingThis 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.
{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.
Name | Value |
SERVER_SOFTWARE | cgitest/1.0 |
SERVER_NAME | localhost |
GATEWAY_INTERFACE | CGI/1.1 |
SERVER_PROTOCOL | HTTP/1.1 |
SERVER_PORT | 80 |
REQUEST_METHOD | GET |
REMOTE_HOST | remote |
REMOTE_ADDR | 127.0.0.1 |
{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.
{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.
{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.
{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)))
Next: www.css
- CSS parsing and construction, Previous: www.cgi
- CGI utility, Up: Library modules - Utilities [Contents][Index]