interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / seed / net

9c63339 chore: remove crumbs, keep the written folder notes in FOLDERS.md Drake Stapleton committed 2026-11-08
..
examples/
tests/
README.md20338
http.om47842
https.om6776
notls.om715

README.md

seed/net: HTTP/1.1 in seeded Omega

http.om is a bounded HTTP/1.1 server and client written in seeded Omega (OM-2 profile), compiled by seed/out/omc. It covers strict message parsing, Content-Length, chunked and close-delimited bodies, keep-alive, pipelining, Expect: 100-continue, deadlines and server-sent events (SSE) in both directions. TLS is not included; see "Transport boundary".

Status: IMPLEMENTED and EXERCISED on a Linux AArch64 host with seed/out/omc sha256 befb8199...8a1d (tests/check.py PASS; the run log is attached to the integration PR). Host only: no hardware or deployment claim.

Files

PathWhat it is
http.omThe library unit. No om2 line, no fn main, no globals.
notls.omThe three transport hooks for a program without TLS (every one returns HENOSUP). Composed after http.om.
https.omThe same three hooks implemented with the om/tls TLS 1.3 client, plus htlsinit / htlsconn / htlsend. Composed after the om/tls units and http.om.
examples/sse_server.omAn embeddable server: /health, /events (SSE), /echo (body up to 1 MiB).
examples/sse_client.omAn incremental SSE client that prints one line per event.
tests/parse.omMemory-mode parser driver for the corpus.
tests/live.omLoopback socket tests: bodies, keep-alive, pipelining, SSE, malformed requests, deadlines, descriptor leaks.
tests/https.omHTTPS GET through https.om: https HOST PORT STOREFILE PATH [CONNECTHOST [IDLEMS [TOTALMS [IOSPARE]]]], body to stdout, status N / HTTPSERR r / TLSDETAIL d to stderr.
tests/nosup.omA program without TLS must refuse every byte on a non-TCP transport.
tests/check.pyHost referee: builds everything, runs the corpus, the mutants, live.om and the curl / http.client end-to-end check.

Building a program

The library has no om2 line, so the application build adds one line in front of the concatenated units:

{ printf 'om2\n'; cat seed/net/http.om seed/net/notls.om app.om; } | seed/out/omc > app

A program that speaks HTTPS composes the om/tls units and https.om instead of notls.om (exactly one of the two, after http.om):

{ printf 'om2\n'
  for u in sha2 hkdf drbg x25519 sha3 mlkem chacha aesgcm ec ecdh rsa x509 rev fips tls; do cat om/tls/$u.om; done
  cat seed/net/http.om seed/net/https.om app.om; } | seed/out/omc > app

A program that also parses JSON adds seed/json/json.om in the same cat. Names in http.om are functions h*, constants H* and texts h*; an application must not reuse them. big, out, part, at, field and the other OM-2 words cannot be names.

Ownership and state

All state belongs to the caller. A connection is two arrays, normally locals of the function that owns the connection:

cs = new ulong HCSLEN 0      state: descriptor, cursors, deadlines, framing, header index
io = new uchar 131072 0      bytes: read region | write region | transport region

hinit cs io fd role splits io into a read region (io[0, HRCAP)), a write region (io[HWB, HWB + HWCAP), a quarter of io, 256 to 65536 bytes, changeable with hsetw) and an empty transport region. Role 1 is a server, 0 a client. hinit takes ownership of fd: hclose cs closes it exactly once, and hinit with fd < 0 selects memory mode (no I/O, hmemld loads a whole message; used by the corpus).

Offsets stored in cs (method, target, header names and values) are absolute offsets into io and stay valid until the next hreqrd / hrsprd on the same cs. Copy what must outlive that. Several connections are several cs/io pairs; nothing is shared between them. Because omc refuses globals as arguments and two parts of one array in one call (error 19), the library uses no global, so there is no single-state limitation: a server may hold as many connections as it has arrays for, and a forked worker gets its own copy.

Bounded epochs: every loop in the library has a bound derived from a buffer size; a connection carries at most HMAXMSG messages (default 1000, set with put cs HMAXMSG n) after which the server answers with Connection: close; a server process serves a bounded number of connections per run (the examples take it as an argument) and is restarted by its supervisor.

Limits (all settable with put cs SLOT v after hinit)

SlotDefaultMeaning
HHEADMXmin(16384, HRCAP / 2)Bytes of one message head, also one chunk-size or trailer line. Over it: HEHEAD.
HHMAX64 (HHSLOTS, the maximum)Header fields per message, also trailer fields. Over it: HEHEAD.
HBCAP1048576Decoded body bytes per message. Over it: HEBIG. Covers the 300 KiB gateway bodies and the 1 MiB catalog cap.
HMAXMSG1000Messages per connection.
HIDLE (hsettmo)30 sLongest single wait for the socket.
HHDLV (hsettmo)30 sDeadline for receiving a whole head, from the start of hreqrd / hrsprd.
HBDLV (hsetbdl)60 sArmed as HDL when a head has been read (that message's body reads and, on a server, the response writes) and when hreqst starts a request (its writes). 0 = none.
HDL (hsetdl)set from HBDLVAbsolute deadline for the following body reads and writes. A long-lived stream (SSE relay) sets its own with hsetdl after the head; hsetdl cs 0 leaves only the idle limit.
HFRMAX65536Chunked framing allowance: chunk-size lines (with extensions), the CRLF after each chunk and trailer lines may total at most HFRMAX + 8 x decoded bytes per message. Over it: HEBIG.

Results

Every function returns a long. Nonnegative is success. Negative values:

ValueNameMeaning (server answers with hreject)
-errnoLinux error from the socket, e.g. -104, -32
-110HETIMEidle wait or deadline passed (408)
-400HEBADmalformed message (400)
-413HEBIGbody over HBCAP, or larger than the caller's array in hbodyall (413)
-417HEEXPExpect other than 100-continue (417)
-431HEHEADhead, line or field count over its cap (431)
-499HETRUNCthe peer closed in the middle of a message (no answer)
-501HETEa transfer coding other than chunked (501)
-505HEVERHTTP major version other than 1, or 1.x with x > 1 (505)
-22, -95HEINVAL, HENOSUPcaller error; unsupported transport

Parsing rules (RFC 9112)

  • Lines end in CRLF. A bare LF or a CR not followed by LF is HEBAD. A server skips empty lines before a request line.
  • Request line: method = 1..32 tchar, one SP, target = 1..8192 bytes 0x21-0x7e in origin form, *, absolute form (scheme://...) or, for CONNECT only, authority form; one SP; HTTP/1.1 or HTTP/1.0. Status line: version, SP, three digits 100..599, SP, reason of field-value bytes (the SP is required even when the reason is empty).
  • Field line: a tchar name, : with no whitespace before it, a value of HTAB, SP, VCHAR and obs-text (no NUL, CR, LF or DEL); leading and trailing SP/HTAB are not part of the value. A line that starts with SP or HTAB (obs-fold) is HEBAD.
  • Content-Length: 1..19 digits on exactly one field line. A repeated field, even with the same value, or a list is HEBAD.
  • Transfer-Encoding: exactly one field line whose value is chunked (any case). Any other coding or list is HETE; with Content-Length or in HTTP/1.0 it is HEBAD.
  • HTTP/1.1 requests need exactly one Host. Connection: close ends the connection after the message; HTTP/1.0 connections always close (no 1.0 keep-alive).
  • Response bodies follow RFC 9112 6.3: none for HEAD, 1xx, 204 and 304; chunked; Content-Length; otherwise close-delimited. hrsprd skips up to 15 interim 1xx responses and returns 101 as final.
  • Chunk sizes are 1..15 hex digits, optionally followed directly by ; and extension bytes (field-value bytes, not otherwise interpreted). Whitespace before ; is HEBAD. Trailer fields are validated like header fields and then discarded.

Server API

lf = hlisten a backlog             a: sockaddr bytes (haddr4 a ip port; port 0 = ephemeral).
                                   The bound address is written back: hport a is the port.
c  = haccept lf tmo                wait at most tmo ns (negative = forever); O_NONBLOCK, CLOEXEC
r  = hinit cs io int c 1           take ownership of c
hsettmo cs idle headdl
hsetbdl cs iv                      body/response deadline per message (default 60 s)
r  = hreqrd cs io                  1 head read; 0 peer closed between requests; < 0 error
     hreject cs io r               answer an error result and mark the connection closing
hismeth cs io m / hispath cs io p  method / path (target before '?') comparisons
i  = hhfind cs io name             header index or -1; value io[hhvoff cs i, + hhvlen cs i)
n  = hbodyrd cs io d               next decoded body bytes into d; 0 at the end
n  = hbodyall cs io d              the whole body (HEBIG when d is too small)
hrspst cs io code                  status line with the standard reason
hhname cs io n / hhval cs io v / hhnum cs io v     one header field; framing fields refused
hhend cs io mode clen              0 Content-Length clen, 1 chunked, 2 close-delimited
hput cs io bytes / hputb cs io b   body bytes (chunked: one chunk per buffer flush)
hflush cs io                       send what is buffered now
hwfin cs io                        end the body; checks a Content-Length body was clen bytes
                                   (hput / hputb already refuse bytes past clen: HEINVAL,
                                   nothing buffered, connection closing)
hrspempty / hrsperr cs io code     a complete empty response (hrsperr also closes)
hnext cs io                        1 = read the next request on this connection, 0 = close
hclose cs

Responses to HEAD keep their framing fields and drop the body bytes; 1xx, 204 and 304 get no framing field and no body. put cs HKEEP 0 before hhend ends the connection after this response. A request body the handler did not read makes hnext return 0.

Client API

fd = hdial a tmo                   nonblocking connect bounded by tmo ns
r  = hinit cs io int fd 0
hreqst cs io method / hreqtg cs io target / hhname / hhval / hhend / hput / hwfin
st = hrsprd cs io                  final status (put cs HISHEAD 1 first after a raw HEAD)
n  = hbodyrd cs io d               Content-Length, chunked or close-delimited

HTTPS (https.om): after hinit and before any I/O, htlsinit cs io host reserves the transport region io[HTB, HTB + TLCSZ) (121696 bytes; io must hold it plus at least 512 bytes of read and write regions) and starts the om/tls client for the TLS name host with ALPN http/1.1; htlsconn cs io st runs the handshake against the trust store st (TLSTSZ bytes filled by tls_store or tls_storef); the request and response functions then work unchanged; htlsend cs io sends close_notify, wipes the keys and closes the descriptor (hclose alone closes the socket without either). A TLS result e comes back as HETLS - e (-601 .. -632, names in tls_errname), a TLS deadline as HETIME. A TCP end of stream without close_notify is HETLS - 4 (truncation), never a clean end of a body. The handshake runs under the same wait policy as every later read: htlsconn hands min(now + idle, HDL, HXDL) to tls_deadline before tls_connect (with all three 0, tls_connect keeps its own 30 s budget). htlsdl cs ms (after hinit, before htlsconn) sets HXDL (cs slot 54), one monotonic deadline ms from now over handshake, request write and response read; 0 clears it, and plain TCP ignores it. A certificate refusal (HETLS - 17) carries its X.509 reason in htlsdet cs io (X5EEXP 2 expired, X5ENYV 3 not yet valid, X5ENAME 4 wrong name, X5EUNK 5 unknown issuer), which survives htlsend; no request byte is sent before the chain, time and name checks pass. There is no fallback to cleartext. tests/https.om is the reference caller.

Server-sent events

Writing: hrspsse sends the 200 head (text/event-stream, Cache-Control: no-cache, chunked), then per event hsseevt (type), hsseid, hsseret (retry ms), hssecmt (comment), hssedat (data; CR, LF and CRLF in it become separate data: lines), and hsseend, which ends the event and flushes it as one chunk. hwfin ends the stream.

Reading (WHATWG HTML 9.2.6): ss = new ulong HSSLEN 0, lb = new uchar N 0 (N >= 256), hsseinit ss. Feed any slice of the body with hssefeed ss lb src; it returns the bytes it consumed and stops after a dispatching line with get ss HSRDY = 1. The event is then: type lb[0, HSELEN) (empty means message), last event id lb[64, 64 + HSILEN), data lb[128, 128 + HSDLEN), retry get ss HSRETRY. Call hssenext ss and feed the rest. Lines may end in CR, LF or CRLF and may be split anywhere between calls; a leading BOM is removed. Event type and id are at most 64 bytes, data plus the current line at most N - 128 bytes (HEHEAD / HEBIG otherwise). A gateway relays an upstream stream incrementally with hbodyrd into a small array, hssefeed, and hsseevt/hsseid/hssedat/hsseend downstream. The default HBDLV deadline (60 s) also covers a stream, so after reading each head the relay calls hsetdl on both connections with its own stream budget (or 0 to keep only the idle limit).

A chunk-size or trailer line that arrives over several receives is scanned once: the scan resumes where it stopped (HBSC) instead of restarting at the line start.

Transport boundary

Every byte crosses three functions only: hrecvio (into the read region), hrecvd (into the caller's body array) and hsendio (from the write region), plus hwait. Sockets are O_NONBLOCK; a call that would block waits with waitio for at most min(idle, deadline - now), so there is no busy wait and no unbounded block. get cs HXPORT selects the transport: 0 is plain TCP or Unix sockets; 1 calls the hooks htlsrecv, htlsrecvd and htlssend, which https.om implements over om/tls (tls_read / tls_write, connection state in the transport region io[HTB, HTB + HTL); before each call the http.om wait policy, min(idle, deadline), is handed to tls_deadline) and notls.om refuses with HENOSUP. Because Omega passes one array to a call once, bytes between the TLS state and the read / write regions of the same io cross a 16 KiB bounce array (one extra copy per record). htlssend refuses an off / n outside io with HEINVAL instead of trapping (om/tls interop row sink, test/tls/bigsend.om). No other function of http.om touches the transport.

Host words used

socknew bind listen accept connect sockname sockopt send recv waitio fclose monons (OMEGESE section 10). No new compiler word is needed. Tests also use `fork waitpid sleepns fopen getdnts`.

Checks

nice -n 19 ionice -c3 python3 seed/net/tests/check.py [--omc seed/out/omc] [--keep DIR]

Prints HTTP-CHECK PASS and exits 0, FAIL (exit 1) or NOT_RUN (exit 3, e.g. no curl). Stages:

  1. Corpus: 105 hand cases with written expectations plus 1500 deterministic fuzz cases (seed 788; generated messages, mutations of framing, whitespace, bytes and truncation, and long chunk extensions). The expected line for each comes from an independent Python reference parser written from RFC
    1. The reference is itself checked against the hand table and, for responses, against the standard library's http.client: a response http.client rejects must be rejected, and one both accept must agree on status, version, fields and body. The corpus caps are head 2048 bytes, 16 fields, body 4096 bytes, chunk framing allowance (HFRMAX) 1024 bytes. The run fails on any missing output line.
  2. Mutants: eleven single-word changes to http.om (for example cl te to cl cl, hex base 16 to 10, ge to gt on the field cap, the chunk framing cap removed); each must compile and must change the corpus output.
  3. tests/live.om: forks a loopback server and checks 300 KiB and 1 MiB request bodies (Content-Length and chunked), 300 KiB responses in both framings, HEAD, two pipelined requests, 40 SSE events read 7 bytes at a time, eight malformed requests and their status, Expect: 100-continue over the cap, no 100 Continue after a flushed final response, a 200 ms head deadline against a stalled client, a 300 ms body deadline against a client that trickles its body inside the idle limit, a 200 ms idle wait against a silent server, refusal of body bytes past a declared Content-Length before any is buffered (client and server roles), refused connections, and that the process ends with the descriptors it started with. Seven further mutants of http.om (head deadline never armed, hclose not closing, SSE CR, chunk-size digit, body deadline not armed, Content-Length overrun not refused, 100 Continue keyed on the write length) must each make live.om fail.
  4. End to end: examples/sse_server.om on an ephemeral port, driven by curl (SSE bytes, -i head bytes, 300 KiB echo with Expect: 100-continue and chunked), http.client (six requests on one keep-alive connection, the last with Connection: close), raw sockets (obs-fold 400, empty connection, HTTP/1.0) and examples/sse_client.om; the server's descriptor count must return to its start value after every connection, and the server must exit 0.
  5. HTTPS (needs openssl): a throwaway PKI (root, leaf for localhost, leaf for another name, leaf of an unrelated root), three Python ssl TLS 1.3 servers and one openssl s_server -www, all on 127.0.0.1 ephemeral ports. tests/nosup.om (built with notls.om) must refuse every byte on HXPORT 1, and its stub mutated to return 0 must fail. tests/https.om (built with om/tls and https.om) runs 25 rows: 6-byte, 300 KiB Content-Length, chunked (chunk sizes 1 .. 60000), fragmented (TLS records of 1 .. 11 bytes) and close-delimited bodies compared byte for byte; the smallest io (TLCSZ + 512) passing and one byte less refused with HEINVAL before any request; a head over the limit (HEHEAD); TCP close without close_notify after a Content-Length head, on a close-delimited body, and inside an incomplete record (each HETLS - 4); a silent server and a silent handshake under a 500 ms idle limit, a silent handshake and a 1-byte-per-250 ms body under a total deadline (HETIME); a cleartext HTTP server (HETLS - 5; it must receive a TLS record, never GET); wrong name, untrusted issuer, expired, not yet valid and self-signed leaves (HETLS - 17 with the X.509 detail, and the server must receive no request); and four openssl s_server -www rows (page, wrong name, untrusted issuer, expired). Thirteen mutants (read dispatch gone, head read error or body truncation taken as end of stream, wait policy not handed to TLS, records not written, handshake not armed, HXDL ignored, io minimum not enforced, detail lost, chain result ignored, validity window or host name not checked) must each fail a row. With TLS_NET=1 two live read-only GETs (www.example.com/, api.github.com/licenses/mit) through the system CA bundle must return 200 with the expected text; without it that part is NOT_RUN.

Every socket in the checks is 127.0.0.1 with a port chosen by the kernel. Nothing contacts port 18091; outside hosts are contacted only by the two TLS_NET=1 rows.

Re-verified 2026-10-26 after refresh onto main c5d981041 with reseeded seed/out/omc 189ada82e00bb440cb41351bd252cc68c54a1b1050051cc42a1df700081c3b54: HTTP-CHECK PASS (same counts).

Re-verified 2026-10-26 on integ/omc-batch2 with the batch 2 seed/out/omc 2c82480596bbdc50cda9626866209ef662d5834f278f839ff4ce0250c495029f: HTTP-CHECK PASS (same counts; HTTP-LIVE-MUTANTS PASS killed=7/7).

Re-verified 2026-10-27 on build/omc-batch3-896-897-898-903 with the batch 3 seed/out/omc 397346de169d78e8a5ce53dce6cf9f0ca56a8f527128165bbfb4fb62a335f93e: HTTP-CHECK PASS (HTTP-LIVE-MUTANTS PASS killed=7/7).