This is the drakma-async Reference Manual, version 0.1.5, generated automatically by Declt version 2.3 "Robert April" on Wed Mar 14 03:49:41 2018 GMT+0.
|• Introduction:||What drakma-async is all about|
|• Systems:||The systems documentation|
|• Files:||The files documentation|
|• Packages:||The packages documentation|
|• Definitions:||The symbols documentation|
|• Indexes:||Concepts, functions, variables and data types|
This is a port of the wonderful drakma library to run on top of cl-async.
This library is now API-compatible with drakma 1.3.4.
drakma-async:http-request takes the same arguments as drakma:http-request,
and does its absolute best to have the exact same behavior, except instead of
returning the values of the HTTP request made, it returns a cl-async future
that is finished with the values of the HTTP request.
Here's a simple usage example (using the blackbird promise implementation):
(defun my-http-request () (catcher (multiple-promise-bind (body status headers) (das:http-request "https://www.google.com/") (format t "Status: ~a~%" status) (format t "Headers: ~s~%" headers) (format t "Body: ~a~%" (if (stringp body) body (babel:octets-to-string body)))) (das:http-eof () (format t "Server hung up unexpectedly =[~%")) (error (e) (format t "Error: ~a~%" e)))) (as:start-event-loop #'my-http-request)
drakma-async comes with a test suite:
(ql:quickload :drakma-async-test) (drakma-async-test:run-tests)
drakma-async works well, but for an HTTP client that supports streaming (both upload and download) more natively, check out carrier. Carrier is built specifically to be used in an asynchronous setting, and may eventually deprecate drakma-async.
This library makes use of the
cl-async-ssl package, which is an add-on package
cl-async to provide SSL functionality.
drakma-async will use SSL by
:drakma-no-ssl is present in
*features* during load/compile
Same goes for the test suite: if
:drakma-no-ssl is present in
when the tests are loaded, no SSL tests are performed.
drakma-async provides a function in the
drakma package called
drakma:http-request, except for that the final value returned is
a closure instead of the finished request values. This closure is to be called
when all content in the response has been returned. This is handled by the
which is able to tell when a response has been completely downloaded. Once the
closure is called, it reads all the data from the http-stream the request was
sent on, and parses it via drakma's normal capabilities.
Obviously the downside to this is that the entire response has to be held in memory. For this reason, this library would be best used for smaller requests and sending large amounts of data as opposed to downloading large amounts of data. Note that there is an issue outlining this problem and a potential fix, but it hasn't been worked on YET.
drakma:http-request-async is now completely
automated through the use of the
rewrite-http-request macro (along with some
tree search/replace functions in util.lisp).
This makes upgrading
drakma-async to use the latest version of drakma as
simple as copying the
http-request function from drakma's request.lisp and
pasting it inside the
(rewrite-http-request ...) macro in drakma-aync's
hijack.lisp. This saves me a lot of time doing manual porting, and makes it
easy to use another version of drakma if that's required.
The main system appears first, followed by any subsystem dependency.
|• The drakma-async system:|
Andrew Danger Lyon <email@example.com>
An asynchronous port of the Drakma HTTP client.
Files are sorted by type and then listed depth-first from the systems components trees.
|• Lisp files:|
|• The drakma-async.asd file:|
|• The drakma-async/package.lisp file:|
|• The drakma-async/util.lisp file:|
|• The drakma-async/http-stream.lisp file:|
|• The drakma-async/rewrite.lisp file:|
|• The drakma-async/drakma.lisp file:|
Packages are listed by definition order.
|• The drakma-async package:|
Definitions are sorted by export status, category, package, and then by lexicographic order.
|• Exported definitions:|
|• Internal definitions:|
|• Exported functions:|
|• Exported conditions:|
This function wraps drakma’s new http-request-async function so you don’t
have to deal with the intricacies. For full documentation on this function,
refer to the docs for drakma:http-request; this library aims to be API
compatible with drakma.
This function returns a cl-async future, which is finished with the following
values of the request (once it returns):
(body status headers uri stream must-close status-text)
This means drakma-async is a prime candidate for using the cl-async future macros: http://orthecreedence.github.com/cl-async/future#nicer-syntax
Triggered when an HTTP peer closes the connection.
Triggered when an HTTP connection times out.
|• Internal special variables:|
|• Internal macros:|
|• Internal functions:|
This macro automates the conversion from drakma:http-request to be
asynchronous (http-request-async). It does this by performing recursive tree
searches on the main http-request defun and replacing certain pieces with
It was built because I had to keep porting new versions of drakma over by hand. This is all fine and dandy, but why do it by hand when you can automate it. Now I can copy and paste http-request from any drakma version into a (rewrite-http-request ...) macro and all is well in async land.
Given a stream (of type flexi, chunga, or async-stream), grab the underlying socket (or return nil).
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
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
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
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. They
are also ignored on LispWorks.
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"
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
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
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
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
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). Defaults to *default-http-proxy*. PROXY-BASIC-AUTHORIZATION is used like
BASIC-AUTHORIZATION, but for the proxy, and only if PROXY is
true. If the host portion of the uri is present in the *no-proxy-domains* or the NO-PROXY-DOMAINS list then the proxy setting will be ignored for this request.
If NO-PROXY-DOMAINS is set then it will supersede the
*no-proxy-domains* variable. Inserting domains into this list will
allow them to ignore the proxy setting.
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
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 http://weitz.de/flexi-streams/) with a chunked
stream (see http://weitz.de/chunga/) 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
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.
Open a TCP stream to the given uri, determine when a full response has been returned from the host, and then fire the complete callback, at which point the response can be read from the stream.
Replace the first instance of search-item found by searching recursively
through tree. If found, calls the replace-fn on the found item, which is then
injected back into the tree at the same spot search-item was found.
search-item supports wildcards, as explained in the wildcard-equal function.
A recursive equality function that allows some pieces of data to be missing
or unspecified while performing comparisons:
(wildcard-equal ’(1 2 3) ’(1 :* 3)) => t (wildcard-equal ’(1 (3 4) 3) ’(1 :* 3)) => t (wildcard-equal ’(1 2 3 4) ’(1 2 :...)) => t (wildcard-equal ’(1 (2 3) 4) ’(1 (2 :*) 4)) => t (wildcard-equal ’(1 (2 3 4 5) 4) ’(1 (2 :...) 4)) => t
So :* means any item can match, :... means all of the remaining items can match. :* and :... can be changed to your liking via :wildcard-marker and :rest-marker respectively.
|• Concept index:|
|• Function index:|
|• Variable index:|
|• Data type index:|
|Jump to:||D F L|
|drakma-async.asd:||The drakma-async<dot>asd file|
|drakma-async/drakma.lisp:||The drakma-async/drakma<dot>lisp file|
|drakma-async/http-stream.lisp:||The drakma-async/http-stream<dot>lisp file|
|drakma-async/package.lisp:||The drakma-async/package<dot>lisp file|
|drakma-async/rewrite.lisp:||The drakma-async/rewrite<dot>lisp file|
|drakma-async/util.lisp:||The drakma-async/util<dot>lisp file|
|File, Lisp, drakma-async.asd:||The drakma-async<dot>asd file|
|File, Lisp, drakma-async/drakma.lisp:||The drakma-async/drakma<dot>lisp file|
|File, Lisp, drakma-async/http-stream.lisp:||The drakma-async/http-stream<dot>lisp file|
|File, Lisp, drakma-async/package.lisp:||The drakma-async/package<dot>lisp file|
|File, Lisp, drakma-async/rewrite.lisp:||The drakma-async/rewrite<dot>lisp file|
|File, Lisp, drakma-async/util.lisp:||The drakma-async/util<dot>lisp file|
|Lisp File, drakma-async.asd:||The drakma-async<dot>asd file|
|Lisp File, drakma-async/drakma.lisp:||The drakma-async/drakma<dot>lisp file|
|Lisp File, drakma-async/http-stream.lisp:||The drakma-async/http-stream<dot>lisp file|
|Lisp File, drakma-async/package.lisp:||The drakma-async/package<dot>lisp file|
|Lisp File, drakma-async/rewrite.lisp:||The drakma-async/rewrite<dot>lisp file|
|Lisp File, drakma-async/util.lisp:||The drakma-async/util<dot>lisp file|
|Jump to:||D F L|
|Jump to:||F G H M R T W|
|Jump to:||F G H M R T W|
|Internal special variables|
|Internal special variables|
|Jump to:||C D H P S|
|The drakma-async system|
|The drakma-async package|
|The drakma-async package|
|The drakma-async system|
|Jump to:||C D H P S|