net/client
lib/net/client.vklib/net/client.vk
Unified 3-track pure-Veko HTTP/1.1 + HTTPS (TLS 1.3 / PQC) client.
Works identically across --vm, --wasm, and --native with automatic redirect
following (301/302/307/308), timeouts, Bearer/Basic auth helpers, JSON
request/response helpers, and transparent gzip/deflate response decompression.
RequestOpts = struct { headers map[str] = ..., timeout dur = ..., max_redirects i64 = ..., roots_pem str = ..., extra_roots_pem str = ..., ca_file str = ..., pins_sha256 block = ..., pqc bool = ... }
Request options with ergonomic defaults.
HttpResponse = struct { status i64, reason str, headers map[str], body bytes, final_url str }
Structured HTTP response returned by request, get, post, and post-json.
bearer-header = fn [token str] map[str]
Returns a header map with Authorization: Bearer <token>.
basic-header = fn [user str, password str] map[str]
Returns a header map with RFC 7617 Authorization: Basic <base64(user:pass)>.
use [hc = net/client]
h = hc/basic-header 'alice' 'secret'
if (map/get h 'Authorization') != 'Basic YWxpY2U6c2VjcmV0' [ err 'basic auth' ] else [ .ok ]
header = fn [resp HttpResponse, name str, default_val str] str
Looks up a response header case-insensitively (returns default_val if absent).
text-body = fn [resp HttpResponse] str
Returns the response body decoded as a UTF-8 string.
request = fn [method str, target_url str, body bytes, opts RequestOpts] HttpResponse
Executes an HTTP/HTTPS request with redirect handling (301/302/303/307/308).
head = fn [target_url str, opts RequestOpts] HttpResponse
Performs an HTTP/HTTPS HEAD request (returns headers with empty body, preserving Content-Length).
post = fn [target_url str, body bytes, opts RequestOpts] HttpResponse
Performs an HTTP/HTTPS POST request with raw body bytes.
post-json = fn [target_url str, payload any, opts RequestOpts] HttpResponse
JSON-encodes payload and sends an HTTP/HTTPS POST with Content-Type: application/json.
AsyncRequest = struct { method str = ..., url str, headers map[str] = ..., body bytes = ..., timeout dur = ... }
Descriptor for one concurrent non-blocking HTTP/1.1 request in request-batch.
request-batch = fn [reqs block[AsyncRequest]] block
Executes a batch of HTTP/1.1 AsyncRequests concurrently on a single OS readiness reactor
(epoll / kqueue / IOCP+WSAPoll / WASI net-poll) using non-blocking sockets.
Returns a block in matching input order where each entry is an HttpResponse or err.
get-many = fn [urls block[str], opts RequestOpts] block
Performs concurrent non-blocking HTTP GET requests for all urls on a single reactor thread.
Pool = struct { idle map, max_idle i64 = ..., reused i64 = ... }
Reusable HTTP/1.1 keep-alive connection pool keyed by scheme://host:port.
pool-request = fn [mut pool Pool, method str, target_url str, body bytes, opts RequestOpts] HttpResponse
Executes a pooled HTTP/1.1 request reusing or establishing a persistent keep-alive stream.
pool-get = fn [mut pool Pool, target_url str, opts RequestOpts] HttpResponse
Performs a pooled HTTP GET request.