h1_connection (h1 v0.2.1)
View SourceHTTP/1.1 connection gen_statem.
Owns a single TCP or TLS socket and drives the h1_parse_erl parser in both client and server modes. Emits protocol events to the owner pid (or a per-stream handler if set) using a tuple shape identical to erlang_h2 / erlang_quic_h3 so callers can swap protocols:
{h1, Conn, connected} {h1, Conn, {request, StreamId, Method, Path, Headers}} % server {h1, Conn, {response, StreamId, Status, Headers}} % client {h1, Conn, {informational, StreamId, Status, Headers}} % 1xx {h1, Conn, {data, StreamId, Data, EndStream}} {h1, Conn, {trailers, StreamId, Trailers}} {h1, Conn, {upgrade, StreamId, Protocol, Headers}} % server {h1, Conn, {upgraded, StreamId, Protocol, Sock, Buf, Hs}} % client {h1, Conn, {stream_reset, StreamId, Reason}} {h1, Conn, {goaway, LastStreamId, Reason}} {h1, Conn, {closed, Reason}}
Keep-alive, client-side pipelining, Expect: 100-continue, trailers and Upgrade (101 Switching Protocols) are all handled here.
Summary
Functions
Server: reply 200 Connection Established to a classic HTTP/1.1 CONNECT and take ownership of the raw socket in one step. ExtraHeaders are written as-is; no Connection/Upgrade/framing headers are injected, so bytes after the terminating CRLF belong to the tunnel.
Server: reply to an upgrade request. Extra headers are added to the 101 response; Connection: upgrade + Upgrade: <token> are auto-added.
Abort a stream. Because H1 has no RST_STREAM equivalent, this advertises Connection: close and closes the socket once the current exchange is drained.
Server: emit a 100 Continue informational response.
Advertise Connection: close on the next response (server) or on the next request (client), then shut the socket.
Client: send a request. Headers should not include Host/Content-Length (they're auto-added). Returns the assigned stream id.
Server: send a response header block. If Headers does not include Content-Length or Transfer-Encoding, the caller is expected to follow up with chunked send_data/4 + send_trailers/3 / send_data with end_stream=true.
Client: send an Upgrade request and block until either 101 arrives (returning the raw socket) or a non-101 response is received.
Functions
Server: reply 200 Connection Established to a classic HTTP/1.1 CONNECT and take ownership of the raw socket in one step. ExtraHeaders are written as-is; no Connection/Upgrade/framing headers are injected, so bytes after the terminating CRLF belong to the tunnel.
Server: reply to an upgrade request. Extra headers are added to the 101 response; Connection: upgrade + Upgrade: <token> are auto-added.
Abort a stream. Because H1 has no RST_STREAM equivalent, this advertises Connection: close and closes the socket once the current exchange is drained.
Server: emit a 100 Continue informational response.
Advertise Connection: close on the next response (server) or on the next request (client), then shut the socket.
Client: send a request. Headers should not include Host/Content-Length (they're auto-added). Returns the assigned stream id.
Server: send a response header block. If Headers does not include Content-Length or Transfer-Encoding, the caller is expected to follow up with chunked send_data/4 + send_trailers/3 / send_data with end_stream=true.
Client: send an Upgrade request and block until either 101 arrives (returning the raw socket) or a non-101 response is received.