Open Manual

Networking

std.os.net is the facade for HTTP, sockets, local servers, process tubes,

SSH-style workflows, TLS transport, transcripts, and shared network context.

Pick the highest-level API that still exposes the data you need. net.request

covers HTTP, server helpers cover local fixtures, tubes cover interactive

processes or services, and raw sockets cover direct protocol implementations.

Layers

LayerEntry pointResult
HTTP clientnet.requestResponse dictionary with status, headers, body, transport, error metadata.
Local HTTP serverstd.os.net.serverBlocking HTTP/1.1 handler loop for tools and fixtures.
Tube interactionremote, process, shell, sshBuffered send/receive API with transcripts.
Raw socketsocket_connect, socket_bind, socket_acceptDirect protocol-level TCP IO.
Contextnet.contextLog level, timeout, chunk size, color behavior.

Context

Network APIs share context values:

use std.os.net as net

net.context({
   "log_level": "debug",
   "timeout_ms": 3000,
   "chunk_size": 4096,
   "color": false
})

Log levels are quiet, error, info, debug, and trace.

HTTP requests

net.request(options) or net.request(method, url, data, headers, options)

prepares a request and returns a response dictionary.

OptionMeaning
methodHTTP method. Defaults to GET unless a body implies POST.
url / uriFull URL.
params / queryQuery string pairs, dict, list, or raw query string.
headersRequest headers.
jsonJSON body and JSON content type.
formURL-encoded form body.
multipart / fields / filesMultipart body fields and files.
body / dataRaw or form-like body.
cookies / cookieCookie dict or raw cookie header.
auth / bearerBasic or bearer authorization helpers.
user_agent, accept, refererHeader shortcuts.
timeout / timeout_secRequest timeout in seconds.
followRedirect policy.
proxyProxy configuration.
transport, curlTransport selection and curl options.

Response fields:

FieldMeaning
okBoolean success status.
statusNumeric HTTP status.
reasonStatus reason.
headersParsed response headers.
raw_headersRaw header text.
bodyDecoded body string/value where available.
rawRaw response body.
methodFinal method.
urlFinal URL.
transportTransport used.
requestPrepared request metadata.
errorError text when a request fails.

HTTPS uses curl transport when libcurl is available. Plain HTTP can use the

socket transport.

Local HTTP server

std.os.net.server handlers receive a request dictionary and return a response

dictionary or helper result.

ItemBehavior
Request keysmethod, path, query, query_params, headers, body.
Response helpersweb.text, web.html, web.json, web.redirect, web.not_found, web.response.
Header lookupweb.header(headers, name, fallback) is case-insensitive.
CLI serverweb.serve_cli(app, {"port": 8080}) binds a local server and logs requests.

Default no-argument examples use port 8080.

Tubes

Tubes provide buffered interaction with processes, TCP connections, and

SSH-launched commands.

use std.core
use std.os.net as net

net.context({"log_level": "quiet", "timeout_ms": 1000, "color": false})

def io = net.process("/bin/cat", [])
net.sendline(io, "ny")
def out = net.recvuntil(io, "ny\n")
net.close(io)

assert_eq(out, "ny\n", "tube echo")
CallBehavior
remote(host, port, opts)Connect to a TCP service.
connect_retry(host, port, opts)Retry connection until timeout/limit.
process(path, args, opts)Spawn a local process as a tube.
shell(command, opts)Spawn a shell command as a tube.
ssh(opts)Open an SSH-style connection handle.
ssh_process(ssh, command, opts)Run a command through SSH as a tube.
send(io, data)Write bytes/text.
sendline(io, data)Write data plus newline.
recv(io, n)Read up to n bytes.
recvuntil(io, needle)Read through a delimiter and buffer extra bytes.
recvall(io)Read until EOF or configured limit.
sendlineafter(io, needle, data)Receive delimiter, then send a line.
expect(io, patterns)Match expected output patterns.
clean(io)Return buffered data without waiting for more.
transcript_text(io)Return ordered send/receive transcript.
interactive(io)Attach the terminal to the tube.
close(io)Close the tube.

Raw sockets

Raw socket helpers cover direct TCP work:

HelperPurpose
socket_connect(host, port)Open a TCP connection.
socket_bind(host, port)Bind a listening socket.
socket_accept(fd)Accept one incoming connection.
read_socket(fd, n)Read up to n bytes.
read_socket_until(fd, needle)Read until a delimiter or limit.
write_socket_all(fd, data)Write the full buffer.
write_socket_line(fd, data)Write data plus newline.
socket_set_timeout_ms(fd, ms)Set socket timeout.
close_socket(fd)Close the socket fd.

Determinism

Network checks use explicit timeouts. Local servers, process tubes, readiness

checks, and transcript output make network behavior repeatable.

Prefer local services in tests. Public internet calls are useful examples only

when the text names the dependency and the code records timeout and error

metadata.

Failure data

For failing network checks, include: