chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] CGI libs


From: Alejandro Forero Cuervo
Subject: Re: [Chicken-users] CGI libs
Date: Tue, 27 Jul 2004 00:56:25 -0500
User-agent: Mutt/1.5.6+20040523i

Hi, William.

> There  seem  to be  a  few  small, implementation-specific  CGI
> libraries  for scheme,  but I  thought  I'd ask  here first  if
> people know of or have used any they particularly like before I
> embark on on porting or writing my own.

I am attaching the egg that  I use for CGI programming along with
its documentation.  I hope you find it useful.

See the documentation  for details.  Feel free to ask  if you are
in doubt.

You might also want to use my html-stream egg.

As you can see, I use  srfi-40 streams of characters to represent
strings everywhere.  If you give it  a try, I would be interested
in hearing  what you think  of that  kind of programming;  I have
found  that I  like it  myself.  I  am aware  some might  be more
comfortable working  with the usual string  representation, but I
think  using  streams  of  characters has  enough  advantages  to
justify the change.

Felix: if you  consider it appropriate, feel free to  add the egg
to the official list.

Thanks!

Alejo.
http://bachue.com/alejo

---=(  Comunidad de Usuarios de Software Libre en Colombia  )=---               
                                               
---=(  http://bachue.com/colibri )=--=( address@hidden  )=---                   
                                           

Attachment: cgi.scm
Description: Text document

back

CGI

Description:

Library with functionality useful for creating applications that run under CGI.

Author:

Alejandro Forero Cuervo

Version:

This file: $Id: cgi.html 867 2004-07-27 05:31:04Z azul $

Usage:

(require-extension cgi)

Requires:

srfi-40 (compile-time) and stream-ext

Download:

http://anonymous:@svn.afc.no-ip.info/src/home/src/chicken-eggs/cgi/cgi.scm

Documentation:

[procedure] (cgi-main proc)

Initializes internal structures, calls the proc procedure and cleans things up.

proc is passed as its only argument a function used to obtain information received by the CGI from HTML forms (both the QUERY_STRING as well as contents uploaded through HTTP POST requests).

The function passed to proc receives one argument, a symbol, and returns a list with its associated values from the HTTP 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 function passed to proc can only be called before proc returns. It is an error to call it afterwards. This is because the function 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.

(cgi-main (lambda (info)
  (stream-append
    (string->stream "Content-type: text/html\n\n")
    (let ((name (info 'name)))
      (if (null? name)
        expr-evaluating-to-stream-with-html-form
        (string->stream
          (format #f "

Your name is: ~A

" (car name))))))))

The CGI egg still has the following limitations, which might be removed in the future:

  • Does not support form-based file uploads (multipart/form-data).

  • Does not support persistant cookies.

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.


back

reply via email to

[Prev in Thread] Current Thread [Next in Thread]