Common Lisp Package: CLACK.REQUEST

# Clack.Request - Portable HTTP Request object for Clack Request. ## SYNOPSIS (defun app (env) (let ((req (make-request env))) `(200 (:content-type "text/plain") ("Hello, " (query-parameter req "name"))))) ## DESCRIPTION Clack.Request provides a consistent API for request objects. ## AUTHOR * Eitarow Fukamachi (e.arrows@gmail.com)

README:

FUNCTION

Public

MAKE-REQUEST (ENV)

A synonym for (make-instance '<request> ...). Make a <request> instance from environment plist. Raw-body of the instance will be shared, meaning making an instance of <request> doesn't effect on an original raw-body.

SHARED-RAW-BODY (ENV)

Returns a shared raw-body, or returns nil if raw-body is empty. This function modifies REQ to share raw-body among the instances of <request>.

Private

GETF-ALL (PLIST KEY &OPTIONAL (DEFAULT NIL DEFAULT-P))

This is a version of `getf' enabled to manage multiple keys. If the `plist' has two or more pairs that they have given `key' as a key, returns the values of each pairs as one list.

SETFGETF-ALL (VAL PLIST KEY &OPTIONAL (DEFAULT NIL DEFAULT-P))

Changes the stored value(s) of the given `key'. This removes or adds pairs as necessary to store the new list.

MAKE-CIRCULAR-INPUT-STREAM (STREAM &KEY (BUFFER (MAKE-CIRCULAR-STREAM-BUFFER)))

Creates `circular-input-stream' and returns it. If `:buffer' is specified, the instance uses it as an internal buffer. You need this to reuse `circular-input-stream' without saving itself.

MAKE-EXTERNAL-FORMAT (NAME &REST ARGS &KEY (LITTLE-ENDIAN *DEFAULT-LITTLE-ENDIAN*) ID EOL-STYLE)

Creates and returns an external format object as specified. NAME is a keyword like :LATIN1 or :UTF-8, LITTLE-ENDIAN specifies the `endianess' of the external format and is ignored for 8-bit encodings, EOL-STYLE is one of the keywords :CR, :LF, or :CRLF which denote the end-of-line character (sequence), ID is the ID of a Windows code page (and ignored for other encodings).

MAKE-FLEXI-STREAM (STREAM &REST ARGS &KEY (EXTERNAL-FORMAT (MAKE-EXTERNAL-FORMAT ISO-8859-1)) ELEMENT-TYPE COLUMN POSITION BOUND)

Creates and returns a new flexi stream. STREAM must be an open binary or `bivalent' stream, i.e. it must be capable of reading/writing octets with READ-SEQUENCE and/or WRITE-SEQUENCE. The resulting flexi stream is an input stream if and only if STREAM is an input stream. Likewise, it's an output stream if and only if STREAM is an output stream. The default for ELEMENT-TYPE is LW:SIMPLE-CHAR on LispWorks and CHARACTER on other Lisps. EXTERNAL-FORMAT must be an EXTERNAL-FORMAT object or a symbol or a list denoting such an object. COLUMN is the initial column of the stream which is either a non-negative integer or NIL. The COLUMN argument must only be used for output streams. POSITION (only used for input streams) should be an integer and it denotes the position the stream is in - it will be increased by one for each octet read. BOUND (only used for input streams) should be NIL or an integer. If BOUND is not NIL and POSITION has gone beyond BOUND, then the stream will behave as if no more input is available.

MAKE-KEYWORD (NAME)

Interns the string designated by NAME in the KEYWORD package.

NAPPEND (&REST LIST-OF-LIST)

Similar to `nconc` but assures `list` to be rewritten with the result.

PARAMETERS->PLIST (PARAMS &KEY (DELIMITER &))

Convert parameters into plist. The `params' must be a string.

PARSE (INPUT &KEY (OBJECT-KEY-FN *PARSE-OBJECT-KEY-FN*) (OBJECT-AS *PARSE-OBJECT-AS*) (JSON-ARRAYS-AS-VECTORS *PARSE-JSON-ARRAYS-AS-VECTORS*) (JSON-BOOLEANS-AS-SYMBOLS *PARSE-JSON-BOOLEANS-AS-SYMBOLS*) (JSON-NULLS-AS-KEYWORD *PARSE-JSON-NULL-AS-KEYWORD*))

Parse INPUT, which needs to be a string or a stream, as JSON. Returns the lisp representation of the JSON structure parsed. The keyword arguments can be used to override the parser settings as defined by the respective special variables.

PARSE-CONTENT-TYPE (CONTENT-TYPE)

Parse Content-Type from Request header.

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'.

SCAN-TO-STRINGS (REGEX TARGET-STRING &KEY (START 0) (END (LENGTH TARGET-STRING)) SHAREDP)

Like SCAN but returns substrings of TARGET-STRING instead of positions, i.e. this function returns two values on success: the whole match as a string plus an array of substrings (or NILs) corresponding to the matched registers. If SHAREDP is true, the substrings may share structure with TARGET-STRING.

SPLIT (REGEX TARGET-STRING &KEY (START 0) (END (LENGTH TARGET-STRING)) LIMIT WITH-REGISTERS-P OMIT-UNMATCHED-P SHAREDP)

Matches REGEX against TARGET-STRING as often as possible and returns a list of the substrings between the matches. If WITH-REGISTERS-P is true, substrings corresponding to matched registers are inserted into the list as well. If OMIT-UNMATCHED-P is true, unmatched registers will simply be left out, otherwise they will show up as NIL. LIMIT limits the number of elements returned - registers aren't counted. If LIMIT is NIL (or 0 which is equivalent), trailing empty strings are removed from the result list. If REGEX matches an empty string the scan is continued one position behind this match. If SHAREDP is true, the substrings may share structure with TARGET-STRING.

Undocumented

ENSURE-CHARACTER-INPUT-STREAM (STREAM)

MACRO

Private

REGISTER-GROUPS-BIND (VAR-LIST (REGEX TARGET-STRING &KEY START END SHAREDP) &BODY BODY)

Executes BODY with the variables in VAR-LIST bound to the corresponding register groups after TARGET-STRING has been matched against REGEX, i.e. each variable is either bound to a string or to NIL. If there is no match, BODY is _not_ executed. For each element of VAR-LIST which is NIL there's no binding to the corresponding register group. The number of variables in VAR-LIST must not be greater than the number of register groups. If SHAREDP is true, the substrings may share structure with TARGET-STRING.

WHEN-LET (BINDINGS &BODY FORMS)

Creates new variable bindings, and conditionally executes FORMS. BINDINGS must be either single binding of the form: (variable initial-form) or a list of bindings of the form: ((variable-1 initial-form-1) (variable-2 initial-form-2) ... (variable-n initial-form-n)) All initial-forms are executed sequentially in the specified order. Then all the variables are bound to the corresponding values. If all variables were bound to true values, then FORMS are executed as an implicit PROGN.

GENERIC-FUNCTION

Public

Undocumented

BODY-PARAMETER (REQ &OPTIONAL NAME)

COOKIES (REQ &OPTIONAL NAME)

PARAMETER (REQ &OPTIONAL NAME)

QUERY-PARAMETER (REQ &OPTIONAL NAME)

SECUREP (REQ)

Private

Undocumented

GET-WHOLE-OR-SPECIFIED (REQ KEY &OPTIONAL NAME)

SLOT-ACCESSOR

Public

ENV (OBJECT)

Raw env

PATH-INFO (OBJECT)

The remainder of the request URL's path. This may be an empty string if the request URL targets the application root and does not have a trailing slash.

QUERY-STRING (OBJECT)

The portion of the request URL that follows the '?', if any.

REQUEST-METHOD (OBJECT)

The HTTP request method. This must be one of :GET, :HEAD, :OPTIONS, :PUT, :POST, or :DELETE.

REQUEST-URI (OBJECT)

The request URI. Must start with '/'.

SCRIPT-NAME (OBJECT)

The initial portion of the request URL's path, corresponding to the application. This may be an empty string if the application corresponds to the server's root URI. If this key is not empty, it must start with a forward slash (/).

SERVER-NAME (OBJECT)

The resolved server name, or the server IP address.

SERVER-PORT (OBJECT)

The port on which the request is being handled.

SERVER-PROTOCOL (OBJECT)

The version of the protocol the client used to send the request. Typically this will be something like :HTTP/1.0 or :HTTP/1.1.

Undocumented

CLACK-HANDLER (OBJECT)

CONTENT-LENGTH (OBJECT)

CONTENT-TYPE (OBJECT)

RAW-BODY (OBJECT)

REFERER (OBJECT)

REMOTE-ADDR (OBJECT)

REMOTE-PORT (OBJECT)

URI-SCHEME (OBJECT)

USER-AGENT (OBJECT)

Private

Undocumented

CIRCULAR-STREAM-BUFFER (OBJECT)

CLASS

Public

<REQUEST>

Portable HTTP Request object for Clack Request.