Request

is a request data type. It holds the verb of the request, the version, the uri, the cookies, the headers, and the body.

body

instantiate

(Fn [(Ref Request a)] (Ref String a))

gets the body property of a Request.

chunked?

defn

(Fn [(Ref Request a)] Bool)

                        (chunked? r)
                    

checks whether the request body is chunked transfer-encoded, i.e. its Transfer-Encoding header lists chunked (case-insensitively). Decode such a body with TransferEncoding.dechunk.

cookies

instantiate

(Fn [(Ref Request a)] (Ref (Array Cookie) a))

gets the cookies property of a Request.

copy

instantiate

(Fn [(Ref Request a)] Request)

copies a Request.

del

defn

(Fn [URI, (Array Cookie), (Map String (Array String)), String] Request)

                        (del uri cookies headers body)
                    

builds a HTTP DELETE request (version 1.1).

delete

instantiate

(Fn [Request] ())

deletes a Request. Should usually not be called manually.

form-data

defn

(Fn [(Ref Request a)] (Result (Map String String) b))

                        (form-data r)
                    

parses the request body as URL-encoded form data. Returns (Result (Map String String) String).

get

defn

(Fn [URI, (Array Cookie), (Map String (Array String)), String] Request)

                        (get uri cookies headers body)
                    

builds a HTTP GET request (version 1.1).

defn

(Fn [(Ref Request a), (Ref String b)] (Maybe String))

                        (header r name)
                    

gets the first value of a header by name (case-insensitive). Returns (Maybe String).

headers

instantiate

(Fn [(Ref Request a)] (Ref (Map String (Array String)) a))

gets the headers property of a Request.

if-range-matches?

defn

(Fn [(Ref Request a), (Ref (Maybe ETag) b), (Ref (Maybe Datetime) c)] Bool)

                        (if-range-matches? r etag modified)
                    

whether this request's Range header is to be honored for a representation whose entity-tag is etag and whose last modification date is modified. false means the Range is to be ignored and the whole representation sent. See Precondition.if-range-matches?.

ignore-body?

defn

(Fn [(Ref Request a)] Bool)

                        (ignore-body? r)
                    

checks whether the body of the request should be ignored.

init

instantiate

(Fn [String, String, URI, (Array Cookie), (Map String (Array String)), String] Request)

creates a Request.

multipart-data

defn

(Fn [(Ref Request a)] (Result (Array FormPart) String))

                        (multipart-data r)
                    

parses the request body as multipart/form-data, taking the boundary from the Content-Type header. Returns (Result (Array FormPart) String); fails when the request is not multipart/form-data or carries no boundary.

A Request body is a String, and a Carp String ends at its first NUL byte, so a binary upload is already cut short before parse is handed the request text, and cannot be recovered from a Request afterwards. Decoding one means keeping the raw request bytes yourself and calling Multipart.parse-bytes on the body.

negotiate

defn

(Fn [(Ref Request a), (Ref (Array String) b)] (Maybe String))

                        (negotiate r offers)
                    

chooses the best response media type for this request from the server's offers, honoring the request's Accept header (RFC 7231 §5.3.2). A request with no Accept header accepts anything. See Accept.negotiate.

negotiate-encoding

defn

(Fn [(Ref Request a), (Ref (Array String) b)] (Maybe String))

                        (negotiate-encoding r offers)
                    

chooses the best content coding for this request's response from the server's offers, honoring the request's Accept-Encoding header (RFC 9110 §12.5.3). A request with no Accept-Encoding header accepts anything and yields the first offer, whereas one with an empty header accepts only identity. See AcceptEncoding.negotiate.

negotiate-language

defn

(Fn [(Ref Request a), (Ref (Array String) b)] (Maybe String))

                        (negotiate-language r offers)
                    

chooses the best language for this request's response from the server's offers, honoring the request's Accept-Language header (RFC 4647 §3.3.1). A request with no Accept-Language header accepts anything. See AcceptLanguage.negotiate.

parse

defn

(Fn [(Ref String a)] (Result Request String))

                        (parse txt)
                    

parses a HTTP request from a string txt.

Returns an (Error String) holding the error message if it fails, otherwise it will return a (Success Request).

patch

defn

(Fn [URI, (Array Cookie), (Map String (Array String)), String] Request)

                        (patch uri cookies headers body)
                    

builds a HTTP PATCH request (version 1.1).

post

defn

(Fn [URI, (Array Cookie), (Map String (Array String)), String] Request)

                        (post uri cookies headers body)
                    

builds a HTTP POST request (version 1.1).

preconditions

defn

(Fn [(Ref Request a), (Ref (Maybe ETag) b), (Ref (Maybe Datetime) c)] (Maybe Int))

                        (preconditions r etag modified)
                    

the status the conditional request headers of this request demand for a representation whose entity-tag is etag and whose last modification date is modified, as (Maybe Int). Nothing means every precondition held and the request should be answered normally. See Precondition.evaluate.

prn

instantiate

(Fn [(Ref Request a)] String)

converts a Request to a string.

put

defn

(Fn [URI, (Array Cookie), (Map String (Array String)), String] Request)

                        (put uri cookies headers body)
                    

builds a HTTP PUT request (version 1.1).

range

defn

(Fn [(Ref Request a)] (Maybe (Result (Array ByteRangeSpec) String)))

                        (range r)
                    

the byte ranges this request asks for, as (Maybe (Result (Array ByteRangeSpec) String)). Nothing when it carries no Range header. See ByteRange.parse, whose Error means the header is one RFC 9110 §14.2 has the server ignore — serving the whole representation rather than a 416. A request that also carries an If-Range wants if-range-matches? consulted first.

request

defn

(Fn [String, URI, (Array Cookie), (Map String (Array String)), String] Request)

                        (request verb uri cookies headers body)
                    

builds a HTTP 1.1 request.

set-body

instantiate

(Fn [Request, String] Request)

sets the body property of a Request.

set-body!

instantiate

(Fn [(Ref Request a), String] ())

sets the body property of a Request in place.

set-cookies

instantiate

(Fn [Request, (Array Cookie)] Request)

sets the cookies property of a Request.

set-cookies!

instantiate

(Fn [(Ref Request a), (Array Cookie)] ())

sets the cookies property of a Request in place.

set-headers

instantiate

(Fn [Request, (Map String (Array String))] Request)

sets the headers property of a Request.

set-headers!

instantiate

(Fn [(Ref Request a), (Map String (Array String))] ())

sets the headers property of a Request in place.

set-uri

instantiate

(Fn [Request, URI] Request)

sets the uri property of a Request.

set-uri!

instantiate

(Fn [(Ref Request a), URI] ())

sets the uri property of a Request in place.

set-verb

instantiate

(Fn [Request, String] Request)

sets the verb property of a Request.

set-verb!

instantiate

(Fn [(Ref Request a), String] ())

sets the verb property of a Request in place.

set-version

instantiate

(Fn [Request, String] Request)

sets the version property of a Request.

set-version!

instantiate

(Fn [(Ref Request a), String] ())

sets the version property of a Request in place.

str

defn

(Fn [(Ref Request a)] String)

                        (str r)
                    

stringifies the request as it looks on the wire.

The request-target is rendered in origin-form: the path and query of the request’s URI, or / when it has neither, as RFC 9112 §3.2.1 requires of a request sent directly to an origin server. Scheme, host, port, userinfo and fragment stay on the URI and never reach the request line, so the authority has to travel in a Host header.

The other request-target forms of RFC 9112 §3.2 are not produced: absolute-form addresses a proxy, authority-form a CONNECT, and asterisk-form a server-wide OPTIONS.

update-body

instantiate

(Fn [Request, (Ref (Fn [String] String a) b)] Request)

updates the body property of a Request using a function f.

update-cookies

instantiate

(Fn [Request, (Ref (Fn [(Array Cookie)] (Array Cookie) a) b)] Request)

updates the cookies property of a Request using a function f.

update-headers

instantiate

(Fn [Request, (Ref (Fn [(Map String (Array String))] (Map String (Array String)) a) b)] Request)

updates the headers property of a Request using a function f.

update-uri

instantiate

(Fn [Request, (Ref (Fn [URI] URI a) b)] Request)

updates the uri property of a Request using a function f.

update-verb

instantiate

(Fn [Request, (Ref (Fn [String] String a) b)] Request)

updates the verb property of a Request using a function f.

update-version

instantiate

(Fn [Request, (Ref (Fn [String] String a) b)] Request)

updates the version property of a Request using a function f.

uri

instantiate

(Fn [(Ref Request a)] (Ref URI a))

gets the uri property of a Request.

verb

instantiate

(Fn [(Ref Request a)] (Ref String a))

gets the verb property of a Request.

version

instantiate

(Fn [(Ref Request a)] (Ref String a))

gets the version property of a Request.