(use-modules (web response))
As with requests (see Requests), Guile offers a data type for HTTP responses. Again, the body is represented separately from the request.
A predicate and field accessors for the response type. The fields are as follows:
The HTTP version pair, like
(1 . 1).
The HTTP response code, like
The reason phrase, or the standard reason phrase for the response’s code.
The response headers, as an alist of parsed values.
The port on which to read or write a response body, if any.
Read an HTTP response from port.
As a side effect, sets the encoding on port to ISO-8859-1 (latin-1), so that reading one character reads one byte. See the discussion of character sets in Responses, for more information.
Construct an HTTP response object. If validate-headers? is true, the headers are each run through their respective validators.
Adapt the given response to a different HTTP version. Return a new HTTP response.
The idea is that many applications might just build a response for the default HTTP version, and this method could handle a number of programmatic transformations to respond to older HTTP versions (0.9 and 1.0). But currently this function is a bit heavy-handed, just updating the version field.
Write the given HTTP response to port.
Return a new response, whose
response-port will continue writing
on port, perhaps using some transfer encoding.
Some responses, like those with status code 304, are specified as never
having bodies. This predicate returns
#t for those responses.
Note also, though, that responses to
HEAD requests must also not
have a body.
Return an input port from which the body of r can be read. The encoding
of the returned port is set according to r’s
when it’s textual, except if decode? is
when no body is available.
When keep-alive? is
#f, closing the returned port also closes
r’s response port.
Read the response body from r, as a bytevector. Returns
if there was no response body.
Write bv, a bytevector, to the port corresponding to the HTTP response r.
As with requests, the various headers that are typically associated with HTTP responses may be accessed with these dedicated accessors. See HTTP Headers, for more information on the format of parsed headers.
Return the given response header, or default if none was present.
#t if type, a symbol as returned by
response-content-type, represents a textual type such as