Net.HTTP.Request
Requests, as a server receives them and as a client sends them: a method, which carries the body, a target, and header fields.
Two types. A server's Request holds what arrived: the path and query
it was sent to. A client's ClientRequest holds where to send it: a URL.
They share Method and Headers, and HasHeaders builds either, but
their targets differ, and a received request will carry what only a
connection has, which a request being built has no value for.
Records. Both constructors are exported, and their fields are read and
built directly, because each field's type holds its own invariant: a
Method cannot put a body on a GET, and Headers cannot hold a field the
library writes itself. No combination of valid fields is an invalid
request.
A request a server received, routed by matching on it:
match (req.method, req.target.path) {
(GET, "/health") -> ...
(POST(body), "/orders") -> ...
_ -> ...
}
control holds the values of the fields the library reads itself; the functions
below read it. connection is what the server knows of the connection
the request came on: its addresses, and over TLS the name the client asked
for and the protocol chosen.
The values of a request's reserved fields, which headers cannot hold:
contentLength: the body's declared length,Nonefor a chunked body or none.upgrade: the protocolsUpgradeoffered, in order. An offer with a version (HTTP/2.0) is not a token, and is left out.trailers: whetherTEliststrailers, so the client reads trailers after a chunked response.
Returns the length the request's body declared, if it declared one.
Returns the host and port the request was sent to, from Host or from an
absolute-form target.
Returns the protocols the client offered to switch to, in its order of preference, or none.
Returns whether the client reads trailers after a chunked response.
A request a client is to send, built with request and withHeaders:
withHeaders(request(GET, "https://api.example.com/users/1"),
field(Accept, MediaType.json))
url is the target already parsed. A Left is not sent: send reports
it as an error, so request itself never fails, and a URL written as a
literal needs no ?.
What a client can send a request to: an HTTPURL, or a String that
writes one.
Returns a request to t with no headers.
The target of a request a server received, as the codec read it from the
request line and the Host field.
path is encoded, exactly as it arrived (* for OPTIONS *); segments
decodes it. authority is the host and port the request was sent to, from
Host or from an absolute-form target, which must agree. The strings are
the codec's checked input: nothing sends a RequestTarget, so a program
that builds one, to test a handler, cannot put it on the wire.
Returns the path's segments, decoded: /a%20b/c is ["a b", "c"].
Returns None if a segment is not UTF-8 once decoded.