Next: , Previous: Requests, Up: Web


7.3.5 HTTP Responses

     (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.

— Function: response?
— Function: response-version
— Function: response-code
— Function: response-reason-phrase response
— Function: response-headers
— Function: response-port

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.

— Function: read-response port

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.

— Function: build-response [#:version] [#:code] [#:reason-phrase] [#:headers] [#:port]

Construct an HTTP response object. If validate-headers? is true, the headers are each run through their respective validators.

— Function: extend-response r k v . additional

Extend an HTTP response by setting additional HTTP headers k, v. Returns a new HTTP response.

— Function: adapt-response-version response version

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.

— Function: write-response r port

Write the given HTTP response to port.

Returns a new response, whose response-port will continue writing on port, perhaps using some transfer encoding.

— Function: read-response-body/latin-1 r

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 #f if there was no response body.

— Function: write-response-body/latin-1 r body

Write body, a string encodable in ISO-8859-1, to the port corresponding to the HTTP response r.

— Function: read-response-body/bytevector r

Reads the response body from r, as a bytevector. Returns #f if there was no response body.

— Function: write-response-body/bytevector r bv

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.

— Function: response-accept-ranges response [default=#f]
— Function: response-age response [default='()]
— Function: response-allow response [default='()]
— Function: response-cache-control response [default='()]
— Function: response-connection response [default='()]
— Function: response-content-encoding response [default='()]
— Function: response-content-language response [default='()]
— Function: response-content-length response [default=#f]
— Function: response-content-location response [default=#f]
— Function: response-content-md5 response [default=#f]
— Function: response-content-range response [default=#f]
— Function: response-content-type response [default=#f]
— Function: response-date response [default=#f]
— Function: response-etag response [default=#f]
— Function: response-expires response [default=#f]
— Function: response-last-modified response [default=#f]
— Function: response-location response [default=#f]
— Function: response-pragma response [default='()]
— Function: response-proxy-authenticate response [default=#f]
— Function: response-retry-after response [default=#f]
— Function: response-server response [default=#f]
— Function: response-trailer response [default='()]
— Function: response-transfer-encoding response [default='()]
— Function: response-upgrade response [default='()]
— Function: response-vary response [default='()]
— Function: response-via response [default='()]
— Function: response-warning response [default='()]
— Function: response-www-authenticate response [default=#f]

Return the given request header, or default if none was present.