source: project/wiki/stream-cgi @ 12878

Last change on this file since 12878 was 12878, checked in by azul, 12 years ago

Changes applied for azul (193.142.125.1) through svnwiki:

File size: 2.9 KB
Line 
1[[tags:eggs web cgi streams eggspublicdomain]]
2[[toc:]]
3
4== Introduction
5
6The stream-cgi egg is useful for creating applications that run under Common Gateway Interface.
7
8You might find the [[html-stream]] egg useful.
9
10== Examples
11
12The following is a trivial CGI application.
13You can call it using {{?name=alejo}} as its QUERY_STRING.
14
15<enscript highlight=scheme>
16(use stream-cgi html-stream)
17
18(cgi-main
19  (lambda (get post cookies)
20    (stream-append
21      (string->stream "Content-type: text/html\n\n")
22      (let ((name (get 'name)))
23        (if (null? name)
24          (html-stream (html (body (p "Hello, stranger!"))))
25          (html-stream
26            (html
27              (body (p "Hello, " (b (car name)))))))))))
28</enscript>
29
30== Authors
31
32The stream-cgi egg was created by [[Alejandro Forero Cuervo]] <azul@freaks-unidos.net>.
33
34== License
35
36The CGI egg for Chicken Scheme is in the public domain and may be reproduced or copied without
37permission from its author.  Citation of the source is appreciated.
38
39== Requirements
40
41This egg depends on the following:
42
43* [[srfi-40]]
44* [[stream-ext]]
45
46== Creating a CGI application
47
48 [procedure] (cgi-main proc)
49
50Initializes internal structures, calls the
51{{proc}} procedure and, after it returns, cleans things up.
52
53{{proc}} is passed three argument:
54procedures that can used to obtain information received by the CGI from, respectively:
55
56# The {{QUERY_STRING}} (or {{<input>}} objects in HTML forms using method {{GET}})
57# The contents uploaded through HTTP post requests.
58# HTTP cookies.
59
60The functions passed to {{proc}} receive one argument,
61a symbol, and return a list with all its associated values as found on the inputs.
62If no values are found, the empty list
63is returned.  The values are returned as srfi-40 streams of characters;
64values shorter than a given threshold are kept in memory while others
65are stored in temporary files.  This allows the library to use a constant
66amount of memory, regardless of the size of the contents received
67through HTTP.
68
69The functions passed to {{proc}} can not be called after
70{{proc}} returns.
71This is because they may depend on files that get removed
72when {{proc}} returns.
73
74{{proc}} must return a srfi-40 stream with the contents
75to send to the browser, including HTTP headers;
76the actual headers in the HTTP response are generated
77by your web server.
78
79Temporary files are created by the library by means of
80{{(create-temporary-file "chicken-cgi-input")}}.
81You probably want to make sure that the
82{{TMPDIR}}, {{TEMP}} or {{TMP}}
83environment variables are set to a meaningful directory,
84such as {{/tmp}}, where the user your application
85runs as (usually {{nobody}}) has write permissions.
86
87== Version history
88
89=== 1.4
90
91* Implemented parsing of multipart/form-data.
92
93=== 1.3
94
95* Fixed bug in invocation of <code>hash-table-walk</code> [Thanks to Michal Dybizbanski]
96
97=== 1.2
98
99* Adapted to SRFI-69-compatible hash-tables
100
101=== 1.1
102
103* Simple bug fixes
104
105=== 1.0
106
107* First public release
108
Note: See TracBrowser for help on using the repository browser.