(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:
version- The HTTP version pair, like
(1 . 1).code- The HTTP response code, like
200.reason-phrase- The reason phrase, or the standard reason phrase for the response's code.
headers- The response headers, as an alist of parsed values.
port- The port on which to read or write a response body, if any.
Read an HTTP response from port, optionally attaching the given metadata, meta.
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 "HTTP Responses" in the manual, for more information.
Construct an HTTP response object. If validate-headers? is true, the headers are each run through their respective validators.
Extend an HTTP response by setting additional HTTP headers k, v. Returns a new HTTP response.
Adapt the given response to a different HTTP version. Returns 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.
Returns a new response, whose
response-portwill continue writing on port, perhaps using some transfer encoding.
Reads the response body from r, as a string.
Assumes that the response port has ISO-8859-1 encoding, so that the number of characters to read is the same as the
response-content-length. Returns#fif there was no response body.
Write body, a string encodable in ISO-8859-1, to the port corresponding to the HTTP response r.
Reads the response body from r, as a bytevector. Returns
#fif there was no response body.
Write body, 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 request header, or default if none was present.