Common Lisp Package: CLACK.UTIL.HUNCHENTOOT

# Clack.Util.Hunchentoot - Ported from Hunchentoot, Lisp Web server. ## DESCRIPTION Hunchentoot is great product, but it is too huge as a Web server. It has also useful utility. Though I don't like to Clack depends on Hunchentoot. So, I had decided to port needed utilities in Hunchentoot to this package. From such details, only these function and variables, in this file, under BSD-style license, same as Hunchentoot's one. Thanks Edi! ## AUTHOR * Eitarow Fukamachi (e.arrows@gmail.com) * Dr. Edmund Weitz [Original Writer]

README:

FUNCTION

Public

MIME-TYPE (PATHSPEC)

Given a pathname designator PATHSPEC returns the MIME type (as a string) corresponding to the suffix of the file denoted by PATHSPEC (or NIL).

PARSE-RFC2388-FORM-DATA (STREAM CONTENT-TYPE-HEADER EXTERNAL-FORMAT)

Creates an alist of POST parameters from the stream STREAM which is supposed to be of content type 'multipart/form-data'.

URL-DECODE (STRING &OPTIONAL (EXTERNAL-FORMAT *DEFAULT-EXTERNAL-FORMAT*))

Decodes a URL-encoded STRING which is assumed to be encoded using the external format EXTERNAL-FORMAT.

URL-ENCODE (STRING &OPTIONAL (EXTERNAL-FORMAT *DEFAULT-EXTERNAL-FORMAT*))

URL-encodes a string using the external format EXTERNAL-FORMAT.

Private

CONVERT-HACK (STRING EXTERNAL-FORMAT)

The rfc2388 package is buggy in that it operates on a character stream and thus only accepts encodings which are 8 bit transparent. In order to support different encodings for parameter values submitted, we post process whatever string values the rfc2388 package has returned.

MACRO

Private

UPGRADE-VECTOR (VECTOR NEW-TYPE &KEY CONVERTER)

Returns a vector with the same length and the same elements as VECTOR (a variable holding a vector) but having element type NEW-TYPE. If CONVERTER is not NIL, it should designate a function which will be applied to each element of VECTOR before the result is stored in the new vector. The resulting vector will have a fill pointer set to its end. The macro also uses SETQ to store the new vector in VECTOR.

GENERIC-FUNCTION

Private

PARSE-MIME (SOURCE BOUNDARY &KEY WRITE-CONTENT-TO-FILE (WRITE-CONTENT-TO-FILE T))

Parses MIME entities, returning them as a list. Each element in the list is of form: (body headers), where BODY is the contents of MIME part, and HEADERS are all headers for that part. BOUNDARY is a string used to separate MIME entities.

VARIABLE

Private

*DEFAULT-EXTERNAL-FORMAT*

The external format used to compute the REQUEST object.

*MIME-TYPE-HASH*

A hash table which maps file suffixes to MIME types.

*MIME-TYPE-LIST*

An alist where the cars are MIME types and the cdrs are list of file suffixes for the corresponding type.