Common Lisp Package: TRIVIAL-HTTP

trivial-http is a simple networking library for doing HTTP POST and GET over a socket interface. It establishes a package trivial-http, also called SHTTP, from which the following functions are exported: http-get, http-post, escape-url-query and http-head.

README:

FUNCTION

Public

ESCAPE-URL-QUERY (QUERY)

Escapes a query string in accordance with the HTTP specification.

HEADER-PAIR (NAME HEADERS)

Searches headers for name _without_ case sensitivity. Headers should be an alist mapping symbols to values; name a symbol. Returns the (name value) pair if name is found or nil if it is not.

HEADER-VALUE (NAME HEADERS)

Searchers headers for name _without_ case sensitivity. Headers should be an alist mapping symbols to values; name a symbol. Returns the value if name is found or nil if it is not.

HTTP-DOWNLOAD (URL DESTINATION &KEY (SIGNAL-ERROR? T))

Resolves `url` using http-resolve and downloads the contents of the stream it to `destination`. Destination is assumed to be a file. Returns (as multiple values) the number of elements downloaded (e.g., bytes) and the actual URL.

HTTP-GET (URL)

returns a list of three elements: a response code as integer, an association list of headers returned from the server, and a stream from which the response can be read.

HTTP-HEAD (URL)

Returns a list of two elements: a response code as an integer and an association list of headers returned from the server.

HTTP-POST (URL CONTENT-TYPE CONTENT &KEY HEADERS (DEBUG? *HTTP-DEBUG*))

given a URL, a MIME content type, and the content as a character stream, POST to the URL and return the list of three elements as described for [http-get][].

HTTP-RESOLVE (URL &KEY (HTTP-METHOD 'HTTP-GET) (SIGNAL-ERROR? T) (VERBOSE? NIL))

Similar to [http-get][], `http-resolve` returns a list of four elements: the HTTP response code, the headers, the stream and the resolved URL. HTTP-response resolves 301 and 302 responses, and signals an error on responses greater than 400. If there is not an error, then the caller is responsible for closing the HTTP stream.

Private

COPY-STREAM (FROM TO)

Copy into TO from FROM until end of the input stream, in blocks of *stream-buffer-size*. The streams should have the same element type. Returns the total number of 'elements' read and written.

Undocumented

BASE64-ENCODE

DOWNLOAD-STREAM (STREAM DESTINATION &KEY EXPECTED-LENGTH)

OPEN-FILE-ARGUMENTS

RESPONSE-READ-CODE (STREAM)

RESPONSE-READ-HEADERS (STREAM)

URL-HOST (URL)

URL-PATH (URL)

URL-PORT (URL)

URL-RESERVED-CHARACTER-P (C)

WRITE-ADDITIONAL-HEADERS (STREAM)

WRITE-CRLF (STREAM)

WRITE-STANDARD-HEADERS (COMMAND URL HOST STREAM)

GENERIC-FUNCTION

Public

Undocumented

DOWNLOAD-COMMAND (CONDITION)

DOWNLOAD-LENGTH-CLAIMED (CONDITION)

DOWNLOAD-LENGTH-DOWNLOADED (CONDITION)

DOWNLOAD-RESPONSE (CONDITION)

DOWNLOAD-URL (CONDITION)

STREAM-FROM (CONDITION)

STREAM-TO (CONDITION)

VARIABLE

Public

Undocumented

*HTTP-DEBUG*

*USER-AGENT*

Private

Undocumented

*ENCODE-TABLE*

*PROXY-PASSWORD*

*PROXY-USER*

*STREAM-BUFFER-SIZE*

CONDITION

Public

Undocumented

DOWNLOAD-ERROR

INCOMPATIBLE-STREAM-ERROR

MISMATCHED-DOWNLOAD-SIZE-ERROR

Private

Undocumented

TRIVIAL-HTTP-ERROR

CONSTANT

Private

Undocumented

+CRLF+