Common Lisp Package: DRAKMA





Returns true if the cookies COOKIE1 and COOKIE2 are equal. Two cookies are considered to be equal if name and path are equal.


Removes all cookies from COOKIE-JAR which have either expired or which don't have an expiry date.


Reads and parses a `Content-Type' header and returns it as three values - the type, the subtype, and an alist (possibly empty) of name/value pairs for the optional parameters. HEADERS is supposed to be an alist of headers as returned by HTTP-REQUEST. Returns NIL if there is no such header amongst HEADERS.


If HEADERS is an alist of headers as returned by HTTP-REQUEST and NAME is a keyword naming a header, this function returns the corresponding value of this header (or NIL if it's not in HEADERS).


Sends a HTTP request to a web server and returns its reply. URI is where the request is sent to, and it is either a string denoting a uniform resource identifier or a PURI:URI object. The scheme of URI must be `http' or `https'. The function returns SEVEN values - the body of the reply (but see below), the status code as an integer, an alist of the headers sent by the server where for each element the car (the name of the header) is a keyword and the cdr (the value of the header) is a string, the URI the reply comes from (which might be different from the URI the request was sent to in case of redirects), the stream the reply was read from, a generalized boolean which denotes whether the stream should be closed (and which you can usually ignore), and finally the reason phrase from the status line as a string. PROTOCOL is the HTTP protocol which is going to be used in the request line, it must be one of the keywords :HTTP/1.0 or :HTTP/1.1. METHOD is the method used in the request line, a keyword (like :GET or :HEAD) denoting a valid HTTP/1.1 or WebDAV request method, or :REPORT, as described in the Versioning Extensions to WebDAV. Additionally, you can also use the pseudo method :OPTIONS* which is like :OPTIONS but means that an "OPTIONS *" request line will be sent, i.e. the URI's path and query parts will be ignored. If FORCE-SSL is true, SSL will be attached to the socket stream which connects Drakma with the web server. Usually, you don't have to provide this argument, as SSL will be attached anyway if the scheme of URI is `https'. CERTIFICATE is the file name of the PEM encoded client certificate to present to the server when making a SSL connection. KEY specifies the file name of the PEM encoded private key matching the certificate. CERTIFICATE-PASSWORD specifies the pass phrase to use to decrypt the private key. VERIFY can be specified to force verification of the certificate that is presented by the server in an SSL connection. It can be specified either as NIL if no check should be performed, :OPTIONAL to verify the server's certificate if it presented one or :REQUIRED to verify the server's certificate and fail if an invalid or no certificate was presented. MAX-DEPTH can be specified to change the maximum allowed certificate signing depth that is accepted. The default is 10. CA-FILE and CA-DIRECTORY can be specified to set the certificate authority bundle file or directory to use for certificate validation. The CERTIFICATE, KEY, CERTIFICATE-PASSWORD, VERIFY, MAX-DEPTH, CA-FILE and CA-DIRECTORY parameters are ignored for non-SSL requests. PARAMETERS is an alist of name/value pairs (the car and the cdr each being a string) which denotes the parameters which are added to the query part of the URL or (in the case of a POST request) comprise the body of the request. (But see CONTENT below.) The values can also be NIL in which case only the name (without an equal sign) is used in the query string. The name/value pairs are URL-encoded using the FLEXI-STREAMS external format EXTERNAL-FORMAT-OUT before they are sent to the server unless FORM-DATA is true in which case the POST request body is sent as `multipart/form-data' using EXTERNAL-FORMAT-OUT. The values of the PARAMETERS alist can also be pathnames, open binary input streams, unary functions, or lists where the first element is of one of the former types. These values denote files which should be sent as part of the request body. If files are present in PARAMETERS, the content type of the request is always `multipart/form-data'. If the value is a list, the part of the list behind the first element is treated as a plist which can be used to specify a content type and/or a filename for the file, i.e. such a value could look like, e.g., (#p"/tmp/my_file.doc" :content-type "application/msword" :filename "upload.doc"). URL-ENCODER specifies a custom URL encoder function which will be used by drakma to URL-encode parameter names and values. It needs to be a function of one argument. The argument is the string to encode, the return value must be the URL-encoded string. This can be used if specific encoding rules are required. CONTENT, if not NIL, is used as the request body - PARAMETERS is ignored in this case. CONTENT can be a string, a sequence of octets, a pathname, an open binary input stream, or a function designator. If CONTENT is a sequence, it will be directly sent to the server (using EXTERNAL-FORMAT-OUT in the case of strings). If CONTENT is a pathname, the binary contents of the corresponding file will be sent to the server. If CONTENT is a stream, everything that can be read from the stream until EOF will be sent to the server. If CONTENT is a function designator, the corresponding function will be called with one argument, the stream to the server, to which it should send data. Finally, CONTENT can also be the keyword :CONTINUATION in which case HTTP-REQUEST returns only one value - a `continuation' function. This function has one required argument and one optional argument. The first argument will be interpreted like CONTENT above (but it cannot be a keyword), i.e. it will be sent to the server according to its type. If the second argument is true, the continuation function can be called again to send more content, if it is NIL the continuation function returns what HTTP-REQUEST would have returned. If CONTENT is a sequence, Drakma will use LENGTH to determine its length and will use the result for the `Content-Length' header sent to the server. You can overwrite this with the CONTENT-LENGTH parameter (a non-negative integer) which you can also use for the cases where Drakma can't or won't determine the content length itself. You can also explicitly provide a CONTENT-LENGTH argument of NIL which will imply that no `Content-Length' header will be sent in any case. If no `Content-Length' header is sent, Drakma will use chunked encoding to send the content body. Note that this will not work with older web servers. Providing a true CONTENT-LENGTH argument which is not a non-negative integer means that Drakma /must/ build the request body in RAM and compute the content length even if it would have otherwise used chunked encoding, for example in the case of file uploads. CONTENT-TYPE is the corresponding `Content-Type' header to be sent and will be ignored unless CONTENT is provided as well. Note that a query already contained in URI will always be sent with the request line anyway in addition to other parameters sent by Drakma. COOKIE-JAR is a cookie jar containing cookies which will potentially be sent to the server (if the domain matches, if they haven't expired, etc.) - this cookie jar will be modified according to the `Set-Cookie' header(s) sent back by the server. BASIC-AUTHORIZATION, if not NIL, should be a list of two strings (username and password) which will be sent to the server for basic authorization. USER-AGENT, if not NIL, denotes which `User-Agent' header will be sent with the request. It can be one of the keywords :DRAKMA, :FIREFOX, :EXPLORER, :OPERA, or :SAFARI which denote the current version of Drakma or, in the latter four cases, a fixed string corresponding to a more or less recent (as of August 2006) version of the corresponding browser. Or it can be a string which is used directly. ACCEPT, if not NIL, specifies the contents of the `Accept' header sent. RANGE optionally specifies a subrange of the resource to be requested. It must be specified as a list of two integers which indicate the start and (inclusive) end offset of the requested range, in bytes (i.e. octets). If PROXY is not NIL, it should be a string denoting a proxy server through which the request should be sent. Or it can be a list of two values - a string denoting the proxy server and an integer denoting the port to use (which will default to 80 otherwise). PROXY-BASIC-AUTHORIZATION is used like BASIC-AUTHORIZATION, but for the proxy, and only if PROXY is true. If REAL-HOST is not NIL, request is sent to the denoted host instead of the URI host. When specified, REAL-HOST supersedes PROXY. ADDITIONAL-HEADERS is a name/value alist of additional HTTP headers which should be sent with the request. Unlike in PARAMETERS, the cdrs can not only be strings but also designators for unary functions (which should in turn return a string) in which case the function is called each time the header is written. If REDIRECT is not NIL, it must be a non-negative integer or T. If REDIRECT is true, Drakma will follow redirects (return codes 301, 302, 303, or 307) unless REDIRECT is 0. If REDIRECT is an integer, it will be decreased by 1 with each redirect. Furthermore, if AUTO-REFERER is true when following redirects, Drakma will populate the `Referer' header with the URI that triggered the redirection, overwriting an existing `Referer' header (in ADDITIONAL-HEADERS) if necessary. If KEEP-ALIVE is T, the server will be asked to keep the connection alive, i.e. not to close it after the reply has been sent. (Note that this not necessary if both the client and the server use HTTP 1.1.) If CLOSE is T, the server is explicitly asked to close the connection after the reply has been sent. KEEP-ALIVE and CLOSE are obviously mutually exclusive. If the message body sent by the server has a text content type, Drakma will try to return it as a Lisp string. It'll first check if the `Content-Type' header denotes an encoding to be used, or otherwise it will use the EXTERNAL-FORMAT-IN argument. The body is decoded using FLEXI-STREAMS. If FLEXI-STREAMS doesn't know the external format, the body is returned as an array of octets. If the body is empty, Drakma will return NIL. If the message body doesn't have a text content type or if FORCE-BINARY is true, the body is always returned as an array of octets. If WANT-STREAM is true, the message body is NOT read and instead the (open) socket stream is returned as the first return value. If the sixth value of HTTP-REQUEST is true, the stream should be closed (and not be re-used) after the body has been read. The stream returned is a flexi stream (see with a chunked stream (see as its underlying stream. If you want to read binary data from this stream, read from the underlying stream which you can get with FLEXI-STREAM-STREAM. Drakma will usually create a new socket connection for each HTTP request. However, you can use the STREAM argument to provide an open socket stream which should be re-used. STREAM MUST be a stream returned by a previous invocation of HTTP-REQUEST where the sixth return value wasn't true. Obviously, it must also be connected to the correct server and at the right position (i.e. the message body, if any, must have been read). Drakma will NEVER attach SSL to a stream provided as the STREAM argument. CONNECTION-TIMEOUT is the time (in seconds) Drakma will wait until it considers an attempt to connect to a server as a failure. It is supported only on some platforms (currently abcl, clisp, LispWorks, mcl, openmcl and sbcl). READ-TIMEOUT and WRITE-TIMEOUT are the read and write timeouts (in seconds) for the socket stream to the server. All three timeout arguments can also be NIL (meaning no timeout), and they don't apply if an existing stream is re-used. READ-TIMEOUT argument is only available for LispWorks, WRITE-TIMEOUT is only available for LispWorks 5.0 or higher. DEADLINE, a time in the future, specifies the time until which the request should be finished. The deadline is specified in internal time units. If the server fails to respond until that time, a COMMUNICATION-DEADLINE-EXPIRED condition is signalled. DEADLINE is only available on CCL 1.2 and later. If PRESERVE-URI is not NIL, the given URI will not be processed. This means that the URI will be sent as-is to the remote server and it is the responsibility of the client to make sure that all parameters are encoded properly. Note that if this parameter is given, and the request is not a POST with a content-type of `multipart/form-data', PARAMETERS will not be used.


Signals an error of type PARAMETER-ERROR with the provided format control and arguments.


If PARAMETERS is an alist of parameters as returned by, for example, READ-TOKENS-AND-PARAMETERS and NAME is a string naming a parameter, this function returns the full parameter (name and value) - or NIL if it's not in PARAMETERS.


If PARAMETERS is an alist of parameters as returned by, for example, READ-TOKENS-AND-PARAMETERS and NAME is a string naming a parameter, this function returns the value of this parameter - or NIL if it's not in PARAMETERS.


Reads a comma-separated list of tokens from the string STRING. Each token can be followed by an optional, semicolon-separated list of attribute/value pairs where the attributes are tokens followed by a #\= character and a token or a quoted string. Returned is a list where each element is either a string (for a simple token) or a cons of a string (the token) and an alist (the attribute/value pairs). If VALUE-REQUIRED-P is NIL, the value part (including the #\= character) of each attribute/value pair is optional.


Splits the string STRING into a list of substrings separated by commas and optional whitespace. Empty substrings are ignored.


Signals an error of type SYNTAX-ERROR with the provided format control and arguments.


Returns a URL-encoded version of the string STRING using the external format EXTERNAL-FORMAT.



ALIST is supposed to be an alist of name/value pairs where both names and values are strings (or, for values, NIL). This function returns a string where this list is represented as for the content type `application/x-www-form-urlencoded', i.e. the values are URL-encoded using the external format EXTERNAL-FORMAT, the pairs are joined with a #\& character, and each name is separated from its value with a #\= character. If the value is NIL, no #\= is used.


Returns the default port number for the (PURI) URI URI. Works only with the http and https schemes.


The default function used by Drakma to determine how the content body is to be read. See the docstring of *BODY-FORMAT-FUNCTION* for more info.


Accepts a query string as in PURI:URI-QUERY and returns a corresponding alist of name/value pairs.


Signals a warning of type DRAKMA-SIMPLE-WARNING with the provided format control and arguments.


Returns true if the sequence SEQ ends with the sequence SUFFIX. Individual elements are compared with TEST.


Returns a list of COOKIE objects corresponding to the `Set-Cookie' header as found in HEADERS (an alist as returned by HTTP-REQUEST). Collects only cookies which match the domain of the (PURI) URI URI.


Tries to interpret STRING as a string denoting a month and returns the corresponding number of the month. Accepts three-letter abbreviations like "Feb" and full month names likes "February". Finally, the function also accepts strings representing integers from one to twelve.


Tries to interpret STRING as a time zone abbreviation which can either be something like "PST" or "GMT" with an offset like "GMT-02:00".


Creates and returns a closure which can be used as an argument for SEND-CONTENT to send PARAMETERS as a `multipart/form-data' request body using the boundary BOUNDARY.


Generates and returns a random string length LENGTH. The string will consist solely of decimal digits and ASCII letters.


Attaches SSL to the stream HTTP-STREAM and returns the SSL stream (which will not be equal to HTTP-STREAM).


If the (PURI) URI specifies an explicit port number which is different from the default port its scheme, this port number is returned, otherwise NIL.


Reads the message body from the HTTP stream STREAM using the information contained in HEADERS (as produced by HTTP-REQUEST). If TEXTP is true, the body is assumed to be of content type `text' and will be returned as a string. Otherwise an array of octets (or NIL for an empty body) is returned. Returns the optional `trailer' HTTP headers of the chunked stream (if any) as a second value.


Reads one line from STREAM (using Chunga's READ-LINE*) and interprets it as a HTTP status line. Returns a list of two or three values - the protocol (HTTP version) as a keyword, the status code as an integer, and optionally the reason phrase.


Reads and returns (as a two-element list) from STREAM a token and an optional list of parameters (attribute/value pairs) following the token.


Like PARSE-INTEGER, but returns NIL instead of signalling an error.


Sends CONTENT to the stream STREAM as part of the request body depending on the type of CONTENT.


Returns a fresh copy of the HTTP header list ALIST with the `Referer' header set to REFERER-URI. If REFERER-URI is NIL, the result will be a list of headers without a `Referer' header.


Reads and consumes from STREAM any number of commas and whitespace. Returns the following character or NIL in case of END-OF-FILE.


Returns true if the sequence SEQ starts with the sequence PREFIX whereby the elements are compared using TEST.


Returns a true value iff the combination of TYPE and SUBTYPE matches an entry of *TEXT-CONTENT-TYPES*. See docstring of *TEXT-CONTENT-TYPES* for more info.


If the PRESERVE-URI argument is used, the URI needs to be passed to the server in unmodified form. This function returns just the path component of the URI with no URL encoding or other modifications done.


Updates the cookies in COOKIE-JAR by replacing those which are equal to a cookie in (the list) NEW-COOKIES with the corresponding `new' cookie and adding those which are really new.


Returns a corresponding user agent string if TOKEN is one of the keywords :DRAKMA, :FIREFOX, :EXPLORER, :OPERA, or :SAFARI. Returns TOKEN itself otherwise.






A version of DEFCONSTANT for, cough, /strict/ CL implementations.


Evaluates EXPR, binds it to VAR, and executes BODY if VAR has a true value.


Kludge to make Chunga tokenizing functionality usable. Works like WITH-INPUT-FROM-STRING, but creates a sequence of octets that works with CHUNGA::PEEK-CHAR* and friends.


Syntax: WITH-UNIQUE-NAMES ( { var | (var x) }* ) declaration* form* Executes a series of forms with each VAR bound to a fresh, uninterned symbol. The uninterned symbol is as if returned by a call to GENSYM with the string denoted by X - or, if X is not supplied, the string denoted by VAR - as argument. The variable bindings created are lexical unless special declarations are specified. The scopes of the name bindings and declarations do not include the Xs. The forms are evaluated in order, and the values of all but the last are discarded (that is, the body is an implicit PROGN).









A function which determines whether the content body returned by the server is text and should be treated as such or not. The function is called after the request headers have been read and it must accept two arguments, headers and external-format-in, where headers is like the third return value of HTTP-REQUEST while external-format-in is the HTTP-REQUEST argument of the same name. It should return NIL if the body should be regarded as binary content, or a FLEXI-STREAMS external format (which will be used to read the body) otherwise. This function will only be called if the force-binary argument to HTTP-REQUEST is NIL. The initial value of this variable is a function which uses *TEXT-CONTENT-TYPES* to determine whether the body is text and then proceeds as described in the HTTP-REQUEST documentation entry.


The default value for the external format keyword arguments of HTTP-REQUEST. The value of this variable will be interpreted by FLEXI-STREAMS. The initial value is the keyword :LATIN-1. (Note that Drakma binds *DEFAULT-EOL-STYLE* to :LF).


If this variable is not NIL, it should be bound to a stream to which incoming and outgoing headers will be written for debugging purposes.


Determines how duplicate cookies in the response are handled, defaults to T. Cookies are considered duplicate using COOKIE=. Valid values are: NIL - duplicates will not be removed, T or :KEEP-LAST - for duplicates, only the last cookie value will be kept, based on the order of the response header, :KEEP-FIRST - for duplicates, only the first cookie value will be kept, based on the order of the response header. Misbehaving servers may send duplicate cookies back in the same Set-Cookie header: HTTP/1.1 200 OK Server: My-hand-rolled-server Date: Wed, 07 Apr 2010 15:12:30 GMT Connection: Close Content-Type: text/html Content-Length: 82 Set-Cookie: a=1; Path=/; Secure, a=2; Path=/; Secure In this case Drakma has to choose whether cookie 'a' has the value '1' or '2'. By default, Drakma will choose the last value specified, in this case '2'. By default, Drakma conforms to RFC2109 HTTP State Management Mechanism, section 4.3.3 Cookie Management: If a user agent receives a Set-Cookie response header whose NAME is the same as a pre-existing cookie, and whose Domain and Path attribute values exactly (string) match those of a pre-existing cookie, the new cookie supersedes the old.


A list of conses which are used by the default value of *BODY-FORMAT-FUNCTION* to decide whether a 'Content-Type' header denotes text content. The car and cdr of each cons should each be a string or NIL. A content type matches one of these entries (and thus denotes text) if the type part is STRING-EQUAL to the car or if the car is NIL and if the subtype part is STRING-EQUAL to the cdr or if the cdr is NIL. The initial value of this variable is the list (("text" . nil)) which means that every content type that starts with "text/" is regarded as text, no matter what the subtype is.



Drakma's version number as a string.


An alist which maps time zone abbreviations to Common Lisp timezones.








Superclass for all conditions related to Drakma.


Superclass for all errors related to Drakma.


Superclass for all warnings related to Drakma.


Signalled if a function was called with inconsistent or illegal parameters.


Signalled if Drakma encounters wrong or unknown syntax when reading the reply from the server.



Like DRAKMA-ERROR but with formatting capabilities.


Like DRAKMA-WARNING but with formatting capabilities.




The HTTP methods (including WebDAV methods) Drakma knows.


Default external format when reading headers.


A list of all HTTP return codes that redirect us to another URI.


A list of HTTP return codes that redirect using a GET method (see


A list of HTTP methods that should be changed to GET in case of redirect (see