|(require (planet neil/scgi:1:2))|
Note: This library is currently being used successfully in a large system. As noted in the API documentation, one feature has not yet been implemented fully, and some documentation remains to be done.
The scgi library implements fast Web CGI using the SCGI protocol. This library is used in conjunction with an HTTP server supporting SCGI, such as Apache Server with the mod_scgi module.
The scgi library also supports running as normal Web CGI without any change to source code, such as during development of an application intended to be deployed using SCGI.
SCGI was specified by Neil Schemenauer in “SCGI: A Simple Common Gateway Interface alternative,” dated 2008-06-23 (http://python.ca/scgi/protocol.txt).
An example usage of this library:
|(require (planet neil/scgi))|
|(let ((my-foo (my-open-foo)))|
|(cgi (lambda ()|
|(and (eq? (cgi-type) 'scgi)|
|(display "Content-type: text/html\r\n\r\n")|
|(display "<p>Hello, world</p>"))|
Note that your Apache Server installation might not have mod_scgi module installed or enabled by default. If you happen to be running Debian Lenny (stable) or similar, this module can be installed via the Debian package libapache2-mod-scgi.
|(cgi startup-proc request-proc shutdown-proc)|
Implement CGI. Normal CGI is used if the REQUEST_URI environment variable is defined; otherwise, SCGI is used.
startup-proc is a thunk that is evaluated once (before listener starts). request-proc is evaluated once for each request (which, in normal CGI, is once). shutdown-proc is evaluated once, as processing of all CGI requests has finished.
For evaluation of request-proc, the default input and output ports are as with normal CGI, regardless of whether normal CGI or SCGI is in use.
In a CGI request context, returns the CGI content length – the number of bytes that can be read from the default input port – as integer.
In a CGI request context, returns the corresponding CGI value as a string.
When called in SCGI mode, this procedure yields an alist of SCGI variables with both the key and value of each pair being byte strings. Calling this procedure in normal CGI mode is an error.
Note that normally you will not need to use this procedure, and will instead use procedures like cgi-request-uri, which work in both SCGI and normal CGI modes.
Returns a symbol indicating the CGI type: normal or scgi. Behavior outside of the cgi form is undefined.
In CGI request context, yields a printable identifying object for the current request that is unique at least for the current requests being handled. This identifying object is intended to be used in debugging messages.
(NOTE: THIS IS NOT YET FULLY IMPLEMENTED AND TESTED.)
Stops processing all CGI requests. This works only within the request-proc of the cgi form.
Version 0.3 – 2010-11-14 – PLaneT (1 2)
Version 0.2 – 2010-10-11 – PLaneT (1 1)
Documentation changes to reflect that it is successfully in use in a real system, and some work remains.
Version 0.1 – 2010-05-25 – PLaneT (1 0)
Initial release. Preliminary.
Copyright (c) 2010 Neil Van Dyke. This program is Free Software; Software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License (LGPL 3), or (at your option) any later version. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See http://www.gnu.org/licenses/ for details. For other licenses and consulting, please contact the author.