Outdated egg!
This is an egg for CHICKEN 3, the unsupported old release. You're almost certainly looking for the CHICKEN 4 version of this egg, if it exists.
If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.
Introduction
The stream-cgi egg is useful for creating applications that run under Common Gateway Interface.
You might find the html-stream egg useful.
Examples
The following is a trivial CGI application. You can call it using ?name=alejo as its QUERY_STRING.
(use stream-cgi html-stream) (cgi-main (lambda (get post cookies) (stream-append (string->stream "Content-type: text/html\n\n") (let ((name (get 'name))) (if (null? name) (html-stream (html (body (p "Hello, stranger!")))) (html-stream (html (body (p "Hello, " (b (car name)))))))))))
This is another way to do the same:
(use stream-cgi stream-ext) (cgi-main (lambda (get post cookies) (with-output-to-stream (lambda () (format #t "Content-type: text/html~%~%<html><body><p>") (let ((name (get 'name))) (if (null? name) (format #t "Hello, stranger!") (format #t "Hello, <b>~A</b>" (stream->string (car name))))) (format #t "</p></body></html>")))))
Authors
The stream-cgi egg was created by Alejandro Forero Cuervo <azul@freaks-unidos.net>.
License
The CGI egg for Chicken Scheme is in the public domain and may be reproduced or copied without permission from its author. Citation of the source is appreciated.
Requirements
This egg depends on the following:
Creating a CGI application
[procedure] (cgi-main proc)
Initializes internal structures, calls the proc procedure and, after it returns, cleans things up.
proc is passed three argument: procedures that can used to obtain information received by the CGI from, respectively:
- The QUERY_STRING (or <input> objects in HTML forms using method GET)
- The contents uploaded through HTTP post requests.
- HTTP cookies.
The functions passed to proc receive one argument, a symbol, and return a list with all its associated values as found on the inputs. If no values are found, the empty list is returned. The values are returned as srfi-40 streams of characters; values shorter than a given threshold are kept in memory while others are stored in temporary files. This allows the library to use a constant amount of memory, regardless of the size of the contents received through HTTP.
The functions passed to proc can not be called after proc returns. This is because they may depend on files that get removed when proc returns.
proc must return a srfi-40 stream with the contents to send to the browser, including HTTP headers; the actual headers in the HTTP response are generated by your web server.
Temporary files are created by the library by means of (create-temporary-file "chicken-cgi-input"). You probably want to make sure that the TMPDIR, TEMP or TMP environment variables are set to a meaningful directory, such as /tmp, where the user your application runs as (usually nobody) has write permissions.
Version history
1.4
- Implemented parsing of multipart/form-data.
1.3
- Fixed bug in invocation of <code>hash-table-walk</code> [Thanks to Michal Dybizbanski]
1.2
- Adapted to SRFI-69-compatible hash-tables
1.1
- Simple bug fixes
1.0
- First public release