Showcase

One call, four carriers.

Four clients, one request, one shape of answer. Everything below was recorded from runs of this library against a local server: the code on the left is the code that ran, and the terminal shows what it printed.

The same call

The only line that differs between the four is the one that makes the connection. After that, the request, the reply and the body are handled by the same four methods.

HTTP/1.1 · RFC 9112
let conn = @h1.connect(host, port~, tls=tls)
let (response, body) = @spec.call(
  conn,
  @spec.Request::new("POST", "/echo", body=@spec.Body::Bytes(b"abcdefghijkl")),
)
print(conn.kind(), response.status, body)
status 200 alpn http/1.1 body abcdefghijkl

On the wire

What the four do to carry that one exchange. Step through it: each line is one thing the client put out or took in.

  1. connect — TCP, then a TLS 1.3 handshake offering http/1.1; the server picks it.
  2. head — POST /echo HTTP/1.1 with host taken from the connection, and content-length: 12.
  3. body — the twelve octets, then nothing more: a declared length ends the request.
  4. reply head — HTTP/1.1 200 OK with its fields, read up to the blank line.
  5. reply body — twelve octets by the same declared length, so the connection is ready for the next exchange.

What differs, and what does not

h1   one exchange per connection, in order
h2   many streams, one connection
h3   many streams, one QUIC connection
ws   messages over an upgraded connection
readiness
open → Stream
send(Stream, Bytes, end~)
response(Stream) → Response
read(Stream) → Bytes?
trailers(Stream) → Array[Field]
the five that never change

is_ready is the one place the difference surfaces: false while an HTTP/1.1 exchange is in flight, true for the other three. A caller that keeps one connection per exchange can ignore it; a pool cannot, which is why the pool asks before it hands a connection out.

The runs behind this page drove the four adapters against a local server over real sockets, and the output above is copied from them rather than written by hand. The guide shows the code each tab stands for in full.