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.

  1. Outdated egg!
  2. http-server-form-posts
    1. Introduction
    2. License
    3. Authors
    4. Requirements
    5. Examples
      1. Canonical Usage
    6. Conversion
      1. request->form-field-list
      2. request->form-field-alist
      3. form-field-list->form-field-alist
    7. Predicates
      1. form-field?
      2. form-field:file-field?
    8. Selectors
      1. form-field:name
      2. form-field:body
      3. form-field:content-type
      4. form-field:file-name
    9. History

http-server-form-posts

Introduction

The http-server-form-posts egg extends the web server available in the http-server egg to include support for parsing of multipart/form-data form posts. It includes some data structures and utilties for representing and inspecting form posts.

License

http-server-form-posts is in the Public Domain and may be reproduced or copied without permission.

Authors

Moe Aboulkheir

Requirements

Examples

Canonical Usage

(use http-server http-server-form-posts)

(http:add-resource "/form-post"
  (lambda (req args)
    (let* ((form-fields (request->form-field-alist req))
           (file-input (alist-ref "file" form-fields string=?))
           (response (string-append
                       "You uploaded a file called "
                       (form-field:file-name file-input)
                       " which has a content type of "
                       (form-field:content-type file-input)
                       ".  The contents of this file are: "
                       (form-field:body file-input))))
       ; ... write the response ...
       )))

Conversion

request->form-field-list

[procedure] (request->form-field-list req)

Returns a list of form-field records, one for each form field that has a part in the body of the HTTP request req, in the same order as the parts appear in the posted document.

request->form-field-alist

[procedure] (request->form-field-alist req)

Same as request->form-field-list, but returns an association list which maps (string) names of form post parts to form-field records.

form-field-list->form-field-alist

[procedure] (form-field-list->form-field-alist req)

Converts a form field list (as returned by request->form-field-list) into the same format as the return value of request->form-field-alist.

Predicates

form-field?

[procedure] (form-field? anything)

Returns a boolean indicating whether anything is of the form-field record type.

form-field:file-field?

[procedure] (form-field:file-field? form-field)

Returns a boolean indicating whether form-field is a file field/file input (i.e. does its content-disposition header have a filename parameter?).

Selectors

form-field:name

[procedure] (form-field:name form-field)

Returns the string name of form-field (i.e. the value of the name parameter of the corresponding content-disposition header).

form-field:body

[procedure] (form-field:body form-field)

Returns the string body of form-field (i.e. the body of its part in the form post).

form-field:content-type

[procedure] (form-field:content-type form-field)

Returns the string content type of form-field (i.e. the value of the content-type header for its part in the form post).

form-field:file-name

[procedure] (form-field:file-name form-field)

Returns the string name of the file whose content is the body of form-field. Will return #f if form-field is not a file field (i.e. if (form-field-file-field? form-field) does not evaluate to #t).

History

0.2
fixed missing filename in .setup script [felix]
0.1
initial version