std/net/httpxchg
std/net/httpxchg — one request over one connection.
Entry: a URL and the pieces of a request.
Exit: an [HttpResponse], with everything this module opened closed
again — on the exception path too.
Two transports, one set of framing rules. The Wire the parser reads
through is what carries that: exchange opens a socket, exchangeSecure
opens a TLS connection, and from speak downwards neither is named
again.
Free functions
| Type | Method and description |
|---|---|
| maxInterim() : i32 Interim responses tolerated before the final one. A 1xx is not the answer to a request: RFC 9110 has the client discardit and keep reading. 103 Early Hints is sent unsolicited by deployedCDNs, so this is an ordinary exchange rather than an edge case — but a peer that only ever sends 1xx is a peer that never answers, and thebound is what makes that a failure instead of a loop. |
| exchange(
timeoutMillis : i32,
url : string,
method : string,
headers : string,
body : string
) : HttpResponse One request/response exchange over one connection. Everything opened here is closed here, on the exception path too: a client that leaked a descriptor per failed request would run out within a retry loop. |
| exchangeSecure(
timeoutMillis : i32,
url : string,
method : string,
headers : string,
body : string,
host : string,
port : i32
) : HttpResponse The same exchange over TLS. A twin rather than a branch inside [ exchange], because the two opendifferent things: axle_tls owns its socket end to end, so there is noSocket here to hand it, and no pair of stream handles to close. |
| speak(
wire : Wire,
url : string,
method : string,
headers : string,
body : string
) : void Render the request head and send it, followed by the body if there is one. The head is rendered from values, not from a request object. Two reasons, and both are load-bearing: assigning an owned string into another class's field gives one allocation two owners, and the second teardown frees what the first released — a segfault the moment the response is read; and a redirect that changes origin has to send a different header block from the one the caller built, without changing the request the caller still holds. |
| listen(wire : Wire, method : string) : HttpResponse Read heads until one of them is an answer, then read the body it frames. A 1xx is an interim status — the server is still working on therequest — and the client's job is to discard it and read the next head. It carries no body, so what it leaves on the wire is the final response, handed to the next readHead as its spill. Treating one as the answerinstead reads the real response as its body, and a caller asking for a page is told 103 about one that returned 200.The first head starts with no spill: this client sends Connection: closeand opens one connection per exchange, so nothing precedes the response on the wire. A caller that reused a connection would pass the previous body's leftover instead. |
| readBody(inp : Wire, head : HttpHead, status : i32, method : string) : HttpBody Read the response body under the framing the head declared. A message that declares its length twice is refused rather than arbitrated: RFC 9112 §6.3 names both Transfer-Encoding besideContent-Length and two Content-Length values that disagree as theshape of request smuggling and response splitting — a peer sending them is making two readers end the message in different places, and whichever this one picked, the leftover would be the head of a message nobody framed. A HEAD response, a 1xx, a 204 and a 304 carry no bodywhatever their headers claim. |
Method detail
#maxInterim
Interim responses tolerated before the final one.
A 1xx is not the answer to a request: RFC 9110 has the client discard
it and keep reading. 103 Early Hints is sent unsolicited by deployed
CDNs, so this is an ordinary exchange rather than an edge case — but a
peer that only ever sends 1xx is a peer that never answers, and the
bound is what makes that a failure instead of a loop.
#exchange
One request/response exchange over one connection.
Everything opened here is closed here, on the exception path too:
a client that leaked a descriptor per failed request would run out
within a retry loop.
#exchangeSecure
The same exchange over TLS.
A twin rather than a branch inside [exchange], because the two open
different things: axle_tls owns its socket end to end, so there is noSocket here to hand it, and no pair of stream handles to close.
#speak
Render the request head and send it, followed by the body if there is
one.
The head is rendered from values, not from a request object. Two
reasons, and both are load-bearing: assigning an owned string into
another class's field gives one allocation two owners, and the second
teardown frees what the first released — a segfault the moment the
response is read; and a redirect that changes origin has to send a
different header block from the one the caller built, without
changing the request the caller still holds.
#listen
Read heads until one of them is an answer, then read the body it frames.
A 1xx is an interim status — the server is still working on the
request — and the client's job is to discard it and read the next head.
It carries no body, so what it leaves on the wire is the final response,
handed to the next readHead as its spill. Treating one as the answer
instead reads the real response as its body, and a caller asking for
a page is told 103 about one that returned 200.
The first head starts with no spill: this client sends Connection: close
and opens one connection per exchange, so nothing precedes the response on
the wire. A caller that reused a connection would pass the previous body's
leftover instead.
#readBody
Read the response body under the framing the head declared.
A message that declares its length twice is refused rather than
arbitrated: RFC 9112 §6.3 names both Transfer-Encoding besideContent-Length and two Content-Length values that disagree as the
shape of request smuggling and response splitting — a peer sending them
is making two readers end the message in different places, and whichever
this one picked, the leftover would be the head of a message nobody
framed. A HEAD response, a 1xx, a 204 and a 304 carry no body
whatever their headers claim.