Version 0.3, 22 August 2004, http://www.neilvandyke.org/httper/
by
Neil W. Van Dyke
<neil@neilvandyke.org>
Copyright © 2003-2004 Neil W. Van Dyke. This program is Free Software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. See the GNU Lesser General Public License [LGPL] for details.
Note: No further work is planned on Httper, since the author plans to
soon obsolete it with a more portable HTTP client library. This version
has been released to migrate from UriFrame to uri.scm, the latter of
which will be used by the new HTTP library. New development is encouraged
to use net/url.ss rather than Httper.
Httper is an HTTP 1.1 [RFC2616] client library for PLT Scheme. It provides multiple levels of abstraction over parts of the HTTP protocol, with the intent that it be convenient for programs with both simple and involved HTTP needs.
Httper requires the packages [Uri.scm] and [SRFI-19-PLT].
Several option parameters affect behavior. The majority of applications will either accept the default values or set the parameters globally.
| current-http-user-agent | Parameter |
|
String for value to send for the HTTP |
| current-max-http-redirects | Parameter |
|
The maximum count of HTTP redirections [RFC2616 sec. 10.3] to follow
automatically, for the |
| current-record-http-times? | Parameter |
|
Boolean value for whether or not to record the times at which specific
states in an HTTP protocol conversation were entered. If |
The exceptions hierarchy is expected to change somewhat in future versions of Httper, so this part of the documentation is intentionally vague.
| exn:httper | Exception |
| exn:httper:proto uri | Exception |
| exn:httper:proto:http detail | Exception |
| exn:httper:proto:transport sub-exn | Exception |
| exn:httper:redirects | Exception |
| exn:httper:status code reason | Exception |
| exn:httper:time | Exception |
| exn:httper:uri uri | Exception |
|
Httper-specific exceptions types, with the subtype hierarchy implied by the colons in the name. |
The http-datetime->date and http-datetime->date-or-false
procedures parse an HTTP full date/time stamp [RFC2616 sec. 3.3.1] into a
struct:date (or struct:srfi19-date) object. The standard
three formats, and some variations on them, are supported. Normally, the
procedures will not be called directly from a program -- methods of
http-request% such as response-last-modified-header/date can
usually be used instead, and may be implemented more efficiently.
| http-datetime->date str | Procedure |
|
Parses the HTTP date/time string str into a (map (lambda (str) (date->string (http-datetime->date str)))
'("Sun, 06 Nov 1994 08:49:37 GMT"
"Sunday, 06-Nov-94 08:49:37 GMT"
"Sun Nov 6 08:49:37 1994"))
=>
("Sun Nov 06 08:49:37Z 1994"
"Sun Nov 06 08:49:37Z 1994"
"Sun Nov 06 08:49:37Z 1994")
|
| http-datetime->date-or-false str | Procedure |
|
Like |
Internal to Httper, HTTP response headers are parsed from an input port
using the parse-http-response-headers procedure. The exact
implementation and representation used might change in a future version of
Httper. Application programs will normally access individual headers
through methods of http-request%.
| parse-http-response-headers in | Procedure |
|
Read HTTP headers from input port in and emit an association list of
name-value pairs. The (parse-http-response-headers
(open-input-string (string-append "Alpha: 1 1 1 \r\n"
"Bravo: 222 \r\n"
" 333 \r\n"
"Charlie: 444 \r\n"
" 555 \r\n"
" 666 \r\n"
"Delta: 7 7 7 \r\n"
"\r\n")))
=>
(("alpha" . "1 1 1")
("bravo" . ("222" "333"))
("charlie" . ("444" "555" "666"))
("delta" . "7 7 7"))
|
Each HTTP request method [RFC2616 sec. 5.1.1] supported by Httper is
implemented as a subclass of http-request%.
| http-request% | Class |
|
Base class for HTTP request. It represents information about the request and response, and has behavior for executing the request. It has various methods for querying response information. It has the optional initialization fields:
|
| uri | Method on http-request% |
| prior-request | Method on http-request% |
| request-referrer | Method on http-request% |
| set-uri! v | Method on http-request% |
| set-prior-request! v | Method on http-request% |
| set-request-referrer! v | Method on http-request% |
|
Methods to get and set the initialization fields. These fields should not be set after the HTTP request has been initiated. |
| initiate-time-seconds | Method on http-request% |
| connect-time-seconds | Method on http-request% |
| status-time-seconds | Method on http-request% |
| headers-time-seconds | Method on http-request% |
|
Methods to fetch the times at which the HTTP protocol entered certain
states, if the value of the |
| response-version-major | Method on http-request% |
| response-version-minor | Method on http-request% |
| response-status-code | Method on http-request% |
| response-status-class | Method on http-request% |
| response-status-reason | Method on http-request% |
|
Once the request execution has received and parsed the response status
line, these methods yield information from the status line.
|
| find-response-header/string-or-list name | Method on http-request% |
| find-response-header/string name | Method on http-request% |
| find-response-header/date name | Method on http-request% |
|
These methods yield a response header value for a given header name in a
requested data type, where name is the string name of the header, in
all lowercase (e.g., The suffix following |
| response-accept-ranges-header | Method on http-request% |
| response-age-header | Method on http-request% |
| response-date-header | Method on http-request% |
| response-etag-header | Method on http-request% |
| response-last-modified-header | Method on http-request% |
| response-location-header | Method on http-request% |
| response-proxy-authenticate-header | Method on http-request% |
| response-retry-after-header | Method on http-request% |
| response-server-header | Method on http-request% |
| response-vary-header | Method on http-request% |
| response-www-authenticate-header | Method on http-request% |
|
Yields a response header value as a string, or |
| response-date-header/date | Method on http-request% |
| response-last-modified-header/date | Method on http-request% |
|
For response headers with date/time values, yields the value as a
|
| execute/nocheck | Method on http-request% |
| execute/nofollow | Method on http-request% |
| execute/follow follow | Method on http-request% |
|
Execute the HTTP request.
(let ((ultimate-request (send request execute/follow #t)))
...)
|
| input-port | Method on http-request% |
| output-port | Method on http-request% |
|
These methods yield an input port and an output port, respectively, to the
server, or |
| close-input | Method on http-request% |
| close-output | Method on http-request% |
| close-ports | Method on http-request% |
|
Closes the response input port, output port, or both, respectively. |
| make-redirect-request | Method on http-request% |
|
When execution of the request has resulted in a redirection response,
invoking this method will yield a new Note that, should the server erroneously supply a relative for the redirection, this method will first resolve that URL relative to the original request URL, and then attempt to force the URL absolute. |
This part of the documentation can be very brief until more HTTP method-specific behavior is added.
| http-get-request% | Class |
| http-head-request% | Class |
|
HTTP method-specific classes. After execution of an
|
A few high-level convenience procedures are provided for instantiating and executing HTTP request objects.
| http-get url [follow [referrer]] | Procedure |
|
The (http-get "http://www.schemers.org/")
=> #<struct:object:http-get-request%>
|
| http-get-content url [follow [referrer]] | Procedure |
|
The (html->sxml (http-get-content "http://www.plt-scheme.org/") #f)
=>
(*top*
(html (head (title "PLT Scheme")
(meta (@ (name "generator") (content "PLT Scheme")))
(style (@ (type "text/css")) ...)
...)
(body (@ (bgcolor "white"))
...))
"\n")
|
| call-with-http-get url proc [follow] | Procedure |
|
Similar to the |
current-force-http-uri-absolute? removed.
Packaging changes.
initiate method closes ports on exception. uri field added
to exn:httper:proto exception.