Module http/index
HTTP/1.1 — the module you import. It is a barrel: it re-exports
./http.yo (the pure types and parsers), ./client.yo (fetch /
fetch_with) and ./server.yo (HttpServer over TcpListener), so
import("std/http") gives the whole surface.
./wire.yo is deliberately NOT re-exported. Message framing —
Content-Length, chunked decoding, and what a read leaves behind — is
shared by the client and the server but is not a public API: it is
std-internal so that the framing rules can change with the pooling work
without that being a breaking change to std/http.
{ fetch } :: import("std/http");
{ IoExn } :: import("std/error");
resp := io.await(fetch(`http://example.com`, io), IoExn(io : io, exn : exn));
println(resp.body);
Stability
unstable, and it inherits rather than owns that: this file declares no
members of its own, so its stability is exactly the union of the three
modules it fronts, each of which carries its own ## Stability section
and its own open question — connection pooling in ./client.yo, the
get_header/HeaderMap duplication in ./http.yo, and the idle timeout
./server.yo needs before it can hold a connection open. What IS stable
about this file is the barrel shape: import("std/http") will keep
exporting those three modules, and adding a fourth would be additive.
Types
HTTP client error variants.
Variants
| Variant | Fields | Description |
|---|---|---|
ConnectionFailed | msg: String | Failed to connect to the remote host. |
InvalidUrl | msg: String | The URL could not be parsed. |
Timeout | The whole request (every connect, write, read and redirect hop) did not
finish within | |
TooManyRedirects | The server kept redirecting past | |
UnsupportedScheme | scheme: String | The URL scheme is neither |
ResponseTooLarge | The raw response (status line, headers and body) grew past
| |
MalformedChunkedBody | msg: String | A |
MalformedContentLength | msg: String | A |
Other | msg: String | An unclassified HTTP error. |
Methods
to_string : (HttpError) fn(inout(self) : HttpError) -> Stringsource : (HttpError) fn(inout(self) : HttpError) -> Option(dyn(ToString + ))The error that caused this one, or .None at the root of the chain.
Rust's Error::source. Defaulted to .None, so an error with nothing
underneath it implements the trait by saying only what it is; a wrapper
overrides it to hand back what it wrapped. Walking the chain to the root
cause works as of 2026-09-14 — the returned Dyn used to lose the
Error trait on an erased receiver, so a caller could print one link but
not follow it (#521,
issues/fixed/self-trait-in-a-return-type-loses-the-trait-on-an-erased-receiver.md).
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpError |
Standard HTTP request methods.
Variants
| Variant | Fields | Description |
|---|---|---|
GET | ||
POST | ||
PUT | ||
DELETE | ||
HEAD | ||
PATCH | ||
OPTIONS |
Methods
clone : (HttpMethod) fn(inout(self) : HttpMethod) -> HttpMethodto_string : (HttpMethod) fn(inout(self) : HttpMethod) -> StringSerialize to wire format, on the status line's own version (so a
parsed response round-trips). A Content-Length header is added
when none is present (the byte length of body), so the peer can
delimit the message without waiting for close.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpMethod |
Returns: String
from_string : (HttpMethod) fn(s : String) -> Option(HttpMethod)Parse a request-line method token (case-sensitive, as RFC 9110 §9.1
requires). .None for anything not in the enum.
Parameters
| Name | Type | Notes |
|---|---|---|
s | String |
Returns: Option(HttpMethod)
An HTTP header as a name-value pair.
Fields
| Name | Type | Description |
|---|---|---|
name | String | |
value | String |
Methods
new : (HttpHeader) fn(name : String, value : String) -> HttpHeaderCreate a new header with the given name and value.
Parameters
| Name | Type | Notes |
|---|---|---|
name | String | |
value | String |
Returns: HttpHeader
A header section — Rust's http::HeaderMap.
Two properties HTTP requires and a HashMap(String, String) cannot give:
- field names are case-insensitive (RFC 9110 §5.1), so
Content-Typeandcontent-typeare the same field. Comparison folds ASCII case; the name is STORED as written, because that is what goes on the wire. - a field may appear more than once (
Set-Cookiealways does), and the order of the repeated values is significant. So this is a multimap that preserves insertion order, backed by a list rather than a hash table.
insert replaces every existing value for a name, append adds one — the
same split Rust draws, and the reason set_header on a request used to
silently accumulate duplicates.
Fields
| Name | Type | Description |
|---|---|---|
_entries | ArrayList(HttpHeader) |
Methods
new : (HeaderMap) fn() -> HeaderMapAn empty header section.
Returns: HeaderMap
len : (HeaderMap) fn(self : HeaderMap) -> usizeNumber of field LINES, counting each repeat of a name separately.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HeaderMap |
Returns: usize
is_empty : (HeaderMap) fn(self : HeaderMap) -> boolget : (HeaderMap) fn(self : HeaderMap, name : String) -> Option(String)get_all : (HeaderMap) fn(self : HeaderMap, name : String) -> ArrayList(String)contains_key : (HeaderMap) fn(self : HeaderMap, name : String) -> boolappend : (HeaderMap) fn(inout(self) : HeaderMap, name : String, value : String) -> unitremove : (HeaderMap) fn(inout(self) : HeaderMap, name : String) -> usizeinsert : (HeaderMap) fn(inout(self) : HeaderMap, name : String, value : String) -> Option(String)entries : (HeaderMap) fn(self : HeaderMap) -> ArrayList(HttpHeader)The field lines in order — for serialization and iteration. The list is a snapshot: pushing to it does not change the map.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HeaderMap |
Returns: ArrayList(HttpHeader)
An HTTP status code — Rust's http::StatusCode.
A u16 newtype rather than a bare integer, so the CLASS predicates
(is_success, is_client_error, ...) live with the value instead of being
re-derived at every call site, and so a status cannot be confused with a
port, a length or a byte count. u16 because RFC 9110 SS15 fixes the range
at three digits: a status is never negative, which an i32 allowed.
Fields
| Name | Type | Description |
|---|---|---|
code | u16 |
Methods
clone : (StatusCode) fn(inout(self) : StatusCode) -> StatusCodefrom_u16 : (StatusCode) fn(code : u16) -> Option(StatusCode)Wrap a raw code, or .None when it is outside the 100-599 range RFC 9110
SS15 defines. An unrecognized code INSIDE the range is accepted — a client
must treat an unknown 4xx as 400, so refusing it would break the very
forward-compatibility the classes exist for.
Parameters
| Name | Type | Notes |
|---|---|---|
code | u16 |
Returns: Option(StatusCode)
as_u16 : (StatusCode) fn(self : StatusCode) -> u16is_informational : (StatusCode) fn(self : StatusCode) -> bool1xx — the request was received and the process continues.
Parameters
| Name | Type | Notes |
|---|---|---|
self | StatusCode |
Returns: bool
is_success : (StatusCode) fn(self : StatusCode) -> boolis_redirection : (StatusCode) fn(self : StatusCode) -> bool3xx — further action is needed to complete the request.
Parameters
| Name | Type | Notes |
|---|---|---|
self | StatusCode |
Returns: bool
is_client_error : (StatusCode) fn(self : StatusCode) -> bool4xx — the request was malformed or cannot be fulfilled.
Parameters
| Name | Type | Notes |
|---|---|---|
self | StatusCode |
Returns: bool
is_server_error : (StatusCode) fn(self : StatusCode) -> bool5xx — the server failed to fulfil an apparently valid request.
Parameters
| Name | Type | Notes |
|---|---|---|
self | StatusCode |
Returns: bool
is_error : (StatusCode) fn(self : StatusCode) -> bool4xx or 5xx — either side's fault, but a failure either way.
Parameters
| Name | Type | Notes |
|---|---|---|
self | StatusCode |
Returns: bool
reason : (StatusCode) fn(self : StatusCode) -> StringThe reason phrase RFC 9110 registers for this code, or Unknown.
The phrase is ADVISORY: a server may send any text and a client must not
act on it — which is why this is a lookup here rather than a field, and
why HttpResponse keeps whatever phrase the peer actually sent.
Parameters
| Name | Type | Notes |
|---|---|---|
self | StatusCode |
Returns: String
to_string : (StatusCode) fn(self : StatusCode) -> StringThe digits alone — what goes in a status line.
Parameters
| Name | Type | Notes |
|---|---|---|
self | StatusCode |
Returns: String
== : (StatusCode) fn(lhs : StatusCode, rhs : StatusCode) -> bool!= : (StatusCode) fn(lhs : StatusCode, rhs : StatusCode) -> bool< : (StatusCode) fn(lhs : StatusCode, rhs : StatusCode) -> bool<= : (StatusCode) fn(lhs : StatusCode, rhs : StatusCode) -> bool> : (StatusCode) fn(lhs : StatusCode, rhs : StatusCode) -> bool>= : (StatusCode) fn(lhs : StatusCode, rhs : StatusCode) -> boolcmp : (StatusCode) fn(lhs : StatusCode, rhs : StatusCode) -> OrderingOK : (StatusCode) fn() -> StatusCodeReturns: StatusCode
CREATED : (StatusCode) fn() -> StatusCodeReturns: StatusCode
ACCEPTED : (StatusCode) fn() -> StatusCodeReturns: StatusCode
NO_CONTENT : (StatusCode) fn() -> StatusCodeReturns: StatusCode
MOVED_PERMANENTLY : (StatusCode) fn() -> StatusCodeReturns: StatusCode
FOUND : (StatusCode) fn() -> StatusCodeReturns: StatusCode
NOT_MODIFIED : (StatusCode) fn() -> StatusCodeReturns: StatusCode
TEMPORARY_REDIRECT : (StatusCode) fn() -> StatusCodeReturns: StatusCode
PERMANENT_REDIRECT : (StatusCode) fn() -> StatusCodeReturns: StatusCode
BAD_REQUEST : (StatusCode) fn() -> StatusCodeReturns: StatusCode
UNAUTHORIZED : (StatusCode) fn() -> StatusCodeReturns: StatusCode
FORBIDDEN : (StatusCode) fn() -> StatusCodeReturns: StatusCode
NOT_FOUND : (StatusCode) fn() -> StatusCodeReturns: StatusCode
METHOD_NOT_ALLOWED : (StatusCode) fn() -> StatusCodeReturns: StatusCode
CONFLICT : (StatusCode) fn() -> StatusCodeReturns: StatusCode
CONTENT_TOO_LARGE : (StatusCode) fn() -> StatusCodeReturns: StatusCode
TOO_MANY_REQUESTS : (StatusCode) fn() -> StatusCodeReturns: StatusCode
INTERNAL_SERVER_ERROR : (StatusCode) fn() -> StatusCodeReturns: StatusCode
NOT_IMPLEMENTED : (StatusCode) fn() -> StatusCodeReturns: StatusCode
BAD_GATEWAY : (StatusCode) fn() -> StatusCodeReturns: StatusCode
SERVICE_UNAVAILABLE : (StatusCode) fn() -> StatusCodeReturns: StatusCode
GATEWAY_TIMEOUT : (StatusCode) fn() -> StatusCodeReturns: StatusCode
An HTTP request with method, path, headers, and optional body.
Fields
| Name | Type | Description |
|---|---|---|
method | HttpMethod | |
path | String | |
headers | HeaderMap | The response's header fields, in the order they arrived. A multimap:
use |
body | String | The body as received, byte-transparent — it is sliced out of the raw
message on the CRLFCRLF boundary and wrapped without UTF-8 validation,
so a binary body survives (a |
Methods
new : (HttpRequest) fn(method : HttpMethod, path : String) -> HttpRequestCreate a new request with the given method and path.
Parameters
| Name | Type | Notes |
|---|---|---|
method | HttpMethod | |
path | String |
Returns: HttpRequest
header : (HttpRequest) fn(self : HttpRequest, name : String, value : String) -> HttpRequestAdd a header and return the request (builder pattern). APPENDS, so a repeatable field can be built up by chaining.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpRequest | |
name | String | |
value | String |
Returns: HttpRequest
with_body : (HttpRequest) fn(self : HttpRequest, body : String) -> HttpRequestSet the request body and return the request (builder pattern).
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpRequest | |
body | String |
Returns: HttpRequest
set_host : (HttpRequest) fn(self : HttpRequest, host : String) -> unitSet the Host header, REPLACING any existing one — there is exactly one Host per request (RFC 9112 SS3.2), and appending a second used to put both on the wire.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpRequest | |
host | String |
Returns: unit
set_header : (HttpRequest) fn(self : HttpRequest, name : String, value : String) -> unitSet a header, REPLACING every existing value for that name. Use
self.headers.append(...) for a field that may legitimately repeat.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpRequest | |
name | String | |
value | String |
Returns: unit
set_body : (HttpRequest) fn(self : HttpRequest, body : String) -> unitget_header : (HttpRequest) fn(self : HttpRequest, name : String) -> Option(String)Look up a header value by name (case-insensitive). The first value, when
the field repeats — self.headers.get_all(name) for all of them.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpRequest | |
name | String |
to_string : (HttpRequest) fn(self : HttpRequest) -> StringSerialize the request to an HTTP/1.1 wire-format string.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpRequest |
Returns: String
An HTTP response with status, headers, and body.
Fields
| Name | Type | Description |
|---|---|---|
status | StatusCode | The status. A |
status_text | String | The reason phrase as the peer sent it, which may be anything (RFC 9110
§15 makes it advisory). |
version | String | The version on the status line, as received — |
headers | HeaderMap | The response's header fields, in the order they arrived. A multimap:
use |
body | String | The body as received, byte-transparent — it is sliced out of the raw
message on the CRLFCRLF boundary and wrapped without UTF-8 validation,
so a binary body survives (a |
Methods
new : (HttpResponse) fn(status : StatusCode, status_text : String) -> HttpResponseCreate a response with the given status and reason phrase.
Parameters
| Name | Type | Notes |
|---|---|---|
status | StatusCode | |
status_text | String |
Returns: HttpResponse
get_header : (HttpResponse) fn(self : HttpResponse, name : String) -> Option(String)Look up a header value by name (case-insensitive). The first value, when
the field repeats — self.headers.get_all(name) for all of them, which
is what Set-Cookie needs.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpResponse | |
name | String |
set_header : (HttpResponse) fn(self : HttpResponse, name : String, value : String) -> unitSet a header, REPLACING every existing value for that name.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpResponse | |
name | String | |
value | String |
Returns: unit
is_ok : (HttpResponse) fn(self : HttpResponse) -> boolis_redirect : (HttpResponse) fn(self : HttpResponse) -> boolis_error : (HttpResponse) fn(self : HttpResponse) -> boolwith_status : (HttpResponse) fn(status : StatusCode) -> HttpResponseA response with status and its registered reason phrase.
Parameters
| Name | Type | Notes |
|---|---|---|
status | StatusCode |
Returns: HttpResponse
header : (HttpResponse) fn(self : HttpResponse, name : String, value : String) -> HttpResponseAdd a header and return the response (builder pattern). APPENDS, so a repeatable field can be built up by chaining.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpResponse | |
name | String | |
value | String |
Returns: HttpResponse
with_body : (HttpResponse) fn(self : HttpResponse, body : String) -> HttpResponseSet the body and return the response (builder pattern).
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpResponse | |
body | String |
Returns: HttpResponse
to_string : (HttpResponse) fn(self : HttpResponse) -> StringSerialize to wire format, on the status line's own version (so a
parsed response round-trips). A Content-Length header is added
when none is present (the byte length of body), so the peer can
delimit the message without waiting for close.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpResponse |
Returns: String
Why a raw HTTP message did not parse — the error of parse_request and
parse_response, which are pure decoders and so return Result (D13).
Each variant carries the offending text; to_string renders the line a
server puts in its 400 body. Until 2026-09-06 the two functions returned
Result(_, String), the one std shape a caller could neither match on nor
distinguish from any other string
(issues/fixed/http-parse-errors-were-bare-strings.md).
Variants
| Variant | Fields | Description |
|---|---|---|
Empty | No start line at all. | |
InvalidStatusLine | line: String | A response whose first line is not |
InvalidStatusCode | text: String | A status code that is not an integer. |
InvalidRequestLine | line: String | A request line that is not exactly |
UnknownMethod | name: String | A request method outside |
UnsupportedVersion | version: String | A request version other than |
InvalidHeaderLine | line: String | A header line without a |
Methods
to_string : (HttpParseError) fn(inout(self) : HttpParseError) -> StringSerialize to wire format, on the status line's own version (so a
parsed response round-trips). A Content-Length header is added
when none is present (the byte length of body), so the peer can
delimit the message without waiting for close.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpParseError |
Returns: String
source : (HttpParseError) fn(inout(self) : HttpParseError) -> Option(dyn(ToString + ))The error that caused this one, or .None at the root of the chain.
Rust's Error::source. Defaulted to .None, so an error with nothing
underneath it implements the trait by saying only what it is; a wrapper
overrides it to hand back what it wrapped. Walking the chain to the root
cause works as of 2026-09-14 — the returned Dyn used to lose the
Error trait on an erased receiver, so a caller could print one link but
not follow it (#521,
issues/fixed/self-trait-in-a-return-type-loses-the-trait-on-an-erased-receiver.md).
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpParseError |
Options for configuring an HTTP request.
Fields
| Name | Type | Description |
|---|---|---|
method | HttpMethod | |
headers | HeaderMap | |
body | String | |
timeout | Option(Duration) | Deadline for the WHOLE request, redirects included — |
max_redirects | usize | How many 3xx |
max_response_bytes | usize | Ceiling on the raw response bytes (headers + body) buffered into
memory before |
Methods
new : (FetchOptions) fn() -> FetchOptionsCreate default options (GET, no headers, empty body, no timeout, 10 redirects, 64 MiB response ceiling).
Returns: FetchOptions
with_method : (FetchOptions) fn(self : FetchOptions, method : HttpMethod) -> FetchOptionsSet the HTTP method.
Parameters
| Name | Type | Notes |
|---|---|---|
self | FetchOptions | |
method | HttpMethod |
Returns: FetchOptions
with_header : (FetchOptions) fn(self : FetchOptions, name : String, value : String) -> FetchOptionsAdd a request header.
Parameters
| Name | Type | Notes |
|---|---|---|
self | FetchOptions | |
name | String | |
value | String |
Returns: FetchOptions
with_body : (FetchOptions) fn(self : FetchOptions, body : String) -> FetchOptionswith_timeout : (FetchOptions) fn(self : FetchOptions, limit : Duration) -> FetchOptionsGive the whole request (redirects included) a deadline.
Parameters
| Name | Type | Notes |
|---|---|---|
self | FetchOptions | |
limit | Duration |
Returns: FetchOptions
with_max_redirects : (FetchOptions) fn(self : FetchOptions, n : usize) -> FetchOptionsCap the number of redirect hops followed (0 = return 3xx verbatim).
Parameters
| Name | Type | Notes |
|---|---|---|
self | FetchOptions | |
n | usize |
Returns: FetchOptions
with_max_response_bytes : (FetchOptions) fn(self : FetchOptions, n : usize) -> FetchOptionsCap the raw response bytes buffered into memory (0 = unlimited).
Parameters
| Name | Type | Notes |
|---|---|---|
self | FetchOptions | |
n | usize |
Returns: FetchOptions
An HTTP client that OWNS a pool of idle keep-alive connections
(reqwest::Client's model, not a process-global one — a std with global
mutable state has no way to say when those sockets close).
Requests made through a client reuse an idle connection to the same target
when there is one, and put it back afterwards unless the exchange said
otherwise (RFC 9112 §9.3 — see _response_keeps_alive). The free fetch
and fetch_with do NOT use a client: they open a connection, announce
Connection: close and close it, exactly as before.
A connection is only ever reused for the same scheme, host and port —
the pool key. Handing an https://a connection to a request for
https://b would speak to the wrong peer under the first peer's
certificate, so the key is checked, never inferred.
dispose closes every idle connection, and close_idle() is the same
operation under a name a caller can invoke (Go's
Transport.CloseIdleConnections). Call close_idle() when you are
done with a client: a client that has made a request does not currently
reach reference count zero, because a ref value passed as a parameter to
an io.async future is never released
(issues/fixed/a-ref-value-passed-to-an-async-future-is-never-released.md), so
the dispose on a scope exit does not yet fire. It is correct and will
start firing when that defect is fixed.
Example
client := HttpClient.new();
a := io.await(client.fetch(`http://127.0.0.1:8080/one`, io), e);
b := io.await(client.fetch(`http://127.0.0.1:8080/two`, io), e); // same socket
client.close_idle(); // both closed
Stability
unstable — new, fetch, fetch_with, with_max_idle,
with_idle_timeout, idle_count and close_idle are intended to keep
their names and meanings; the pool's policies (a TOTAL idle cap, expiry
on the next request rather than on a timer, closing the connection in hand
rather than evicting one already pooled, and retrying only idempotent
methods) are implementation choices that may change.
Fields
| Name | Type | Description |
|---|---|---|
_idle | ArrayList(_Idle) | |
max_idle | usize | Maximum idle connections held at once. When the pool is full a
finished connection is closed instead of stored; |
idle_timeout | Duration | How long a connection may sit idle before it is closed rather than
reused. |
Methods
new : (HttpClient) fn() -> HttpClientA client with an empty pool, DEFAULT_MAX_IDLE_CONNECTIONS idle slots
and a DEFAULT_IDLE_TIMEOUT_SECS age limit.
Returns: HttpClient
with_max_idle : (HttpClient) fn(self : HttpClient, n : usize) -> HttpClientCap the idle connections held at once (0 disables reuse).
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpClient | |
n | usize |
Returns: HttpClient
with_idle_timeout : (HttpClient) fn(self : HttpClient, limit : Duration) -> HttpClientSet the idle age limit (Duration.from_secs(0) lifts it).
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpClient | |
limit | Duration |
Returns: HttpClient
idle_count : (HttpClient) fn(self : HttpClient) -> usizeHow many connections are currently idle in the pool.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpClient |
Returns: usize
close_idle : (HttpClient) fn(self : HttpClient) -> unitClose every idle connection — Go's Transport.CloseIdleConnections.
Connections currently carrying a request are unaffected; they are owned
by their exchange and are closed or pooled when it finishes.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpClient |
Returns: unit
_take : (HttpClient) fn(self : HttpClient, key : String) -> Option(_Idle)_put : (HttpClient) fn(self : HttpClient, key : String, transport : _Transport, carry : Rc(ArrayList(u8))) -> boolParameters
| Name | Type | Notes |
|---|---|---|
self | HttpClient | |
key | String | |
transport | _Transport | |
carry | Rc(ArrayList(u8)) |
Returns: bool
dispose : (HttpClient) fn(self : HttpClient) -> unitRelease the resources self owns — a file descriptor, a socket, a lock,
a buffer the allocator handed out. Called automatically when the value's
owner drops it (a value type) or the last reference to it goes away (a
reference type), so an implementor never calls it directly and must
tolerate being the only one who ever does.
It must be safe to run exactly once, and a type that also exposes an
explicit close/release is responsible for making the second call a
no-op.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpClient |
Returns: unit
fetch : (HttpClient) fn(self : HttpClient, url_str : String, io : Io) -> Impl(Future(HttpResponse, IoExn))GET url_str, reusing an idle connection to the same scheme/host/port
when the pool has one and returning it to the pool afterwards.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpClient | |
url_str | String | |
io | Io |
Returns: Impl(Future(HttpResponse, IoExn))
fetch_with : (HttpClient) fn(self : HttpClient, url_str : String, opts : FetchOptions, io : Io) -> Impl(Future(HttpResponse, IoExn))fetch_with's options, over this client's connection pool.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpClient | |
url_str | String | |
opts | FetchOptions | |
io | Io |
Returns: Impl(Future(HttpResponse, IoExn))
An HTTP/1.1 server bound to a TcpListener.
Fields
| Name | Type | Description |
|---|---|---|
listener | TcpListener | |
max_request_bytes | usize | Requests larger than this are answered with |
stopped | bool |
Methods
bind : (HttpServer) fn(addr : SocketAddr, io : Io) -> Impl(Future(HttpServer, IoExn))Bind a listening socket on addr (port 0 picks a free port — read it
back with local_addr()).
Parameters
| Name | Type | Notes |
|---|---|---|
addr | SocketAddr | |
io | Io |
Returns: Impl(Future(HttpServer, IoExn))
local_addr : (HttpServer) fn(self : HttpServer) -> SocketAddrwith_max_request_bytes : (HttpServer) fn(self : HttpServer, n : usize) -> HttpServerSet the request-size ceiling (builder pattern; 0 = unlimited).
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpServer | |
n | usize |
Returns: HttpServer
serve_once : (HttpServer) fn(self : HttpServer, handler : Impl(Fn(HttpRequest) -> HttpResponse), io : Io) -> Impl(Future(unit, IoExn))Accept ONE connection, read one request, run handler, write the
response and close. A request that does not parse gets a 400 Bad Request whose body names the defect, without calling handler; a
framing defect (oversize, unreadable Content-Length, malformed
chunking) is answered the same way (413 for oversize) instead of being
thrown out of the server
(issues/fixed/one-malformed-request-killed-http-server-serve.md).
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpServer | |
handler | Impl(Fn(HttpRequest) -> HttpResponse) | |
io | Io |
Returns: Impl(Future(unit, IoExn))
serve : (HttpServer) fn(self : HttpServer, handler : Impl(Fn(HttpRequest) -> HttpResponse), io : Io) -> Impl(Future(unit, IoExn))Serve connections one after another until stop() has been called
(checked after each connection completes).
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpServer | |
handler | Impl(Fn(HttpRequest) -> HttpResponse) | |
io | Io |
Returns: Impl(Future(unit, IoExn))
stop : (HttpServer) fn(self : HttpServer) -> unitAsk serve to return after the connection it is currently handling.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpServer |
Returns: unit
close : (HttpServer) fn(self : HttpServer, io : Io) -> Impl(Future(unit, IoExn))Close the listening socket.
Parameters
| Name | Type | Notes |
|---|---|---|
self | HttpServer | |
io | Io |
Returns: Impl(Future(unit, IoExn))
Functions
Parameters
| Name | Type | Notes |
|---|---|---|
raw | String |
Returns: Result(HttpResponse, HttpParseError)
Parameters
| Name | Type | Notes |
|---|---|---|
raw | String |
Returns: Result(HttpRequest, HttpParseError)
Parameters
| Name | Type | Notes |
|---|---|---|
url_str | String | |
opts | FetchOptions | |
io | Io |
Returns: Impl(Future(HttpResponse, IoExn))
Parameters
| Name | Type | Notes |
|---|---|---|
url_str | String | |
io | Io |
Returns: Impl(Future(HttpResponse, IoExn))
Constants
Value: 10
Value: 67108864
Value: 16
Value: 30
Value: 16777216