fastcgi
TOC »
Description
Bindings for the FCGX API of libfcgi.
Author
Usage
(import fastcgi)
Documentation
This egg provides a high-level interface to the FCGX API of libfcgi, part of the FastCGI Devkit.
fcgi-accept-loop
- fcgi-accept-loop SOCKET/PORT BACKLOG CALLBACKprocedure
Given either the filename of a UNIX local socket (string) or a port (integer) as its first argument, this procedure opens a socket and starts a loop for accepting FastCGI requests. An exception is raised if there is an error opening/listening on the socket. Every time a request is accepted, the CALLBACK argument is called with four procedure arguments which will be refered to as 'in', 'out', 'err' and 'env' in the documentation below. The BACKLOG argument is passed to the listen system call.
If the callback returns #f, the accept loop is terminated.
in
- in #!optional INTprocedure
[This procedure is passed to the CALLBACK argument of fcgi-accept-loop.]
If called with no arguments, this procedure reads in as much data as possible from the input stream, returning #f if the stream is empty, and a string otherwise. If called with a single integer argument, it reads exactly the specified number of characters from the stream (and will block indefinitely if the stream is empty or contains too few characters).
In either case, an exception is raised if there is an error reading from the stream.
Don't use (in) to read in post data, since there is no guarantee that it will read all of it. Instead, call in with the value of the HTTP_CONTENT_LENGTH environment variable, or use the fcgi-get-post-data procedure.
The variable *fcgi-slurp-chunk-size* determines the size of the input buffer which will be allocated by a zero-argument call to in. The value of this variable does not affect the maximum amount of input which can be read in, since additional buffers are automatically allocated as necessary.
out
- out STRINGprocedure
[This procedure is passed to the CALLBACK argument of fcgi-accept-loop.]
Writes STRING to the output stream, raising an exception if there is an error.
Note: In order to pass output from functions that print to standard output instead of returning a string, such as sxml-transforms functions, you could encapsulate the function like this
(out (with-output-to-string (lambda () <function>)))
err
- err STRINGprocedure
[This procedure is passed to the CALLBACK argument of fcgi-accept-loop.]
Writes STRING to the error stream, raising an exception if there is an error.
env
- env #!optional VARNAME DEFAULTprocedure
[This procedure is passed to the CALLBACK argument of fcgi-accept-loop.]
If called with no arguments, this procedure returns a list of (name . value) pairs giving the name and value of every variable in the environment. If called with a single argument VARNAME, it returns the value of the specified variable, or #fif that variable is not set.
VARNAME may optionally be followed by a second argument, which specifies a default value to be returned if the variable is not set. (env X) is thus equivalent to (env X #f).
Note that this procedure cannot be called after another request has been accepted, since libfcgi does not maintain environments from previous requests (you will most likely get a segfault). However, an old environment can easily be saved if necessary by storing the return value of (env).
fcgi-get-post-data
- fcgi-get-post-data IN ENVprocedure
Given an IN procedure and an ENV procedure, this procedure returns a string containing the post data for the last request, or #f if the last request was not a post request.
Example
A file named example.scm is included in the egg.
Changelog
- 1.1.1 pointer->c-pointer fix; output strings can contain NULs (thanks to Peter Danenberg)
- 1.1 Port to Chicken 4
- 1.0.1 Bug fix (thanks to Maria Rekouts)
- 1.0 First version
License
Copyright (c) 2006, Alex Drummond <a.d.drummond@googlemail.com>, with contributions from Maria Rekouts, Nikolay Zavaritsky and Joachim Schipper. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. * The name of the author(s) may not be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.