Skip to main content

Module http_client

Module http_client 

Source
Expand description

HTTP client operations for Seq.

Replaces the ureq-era client with a hand-rolled HTTP/1.1 implementation that yields the strand on every IO step. Sits on top of the may-aware DNS, TCP, and TLS layers from PR1-PR3 and maintains its own connection pool keyed by (scheme, host, port).

§API (unchanged from the ureq-era surface)

"https://api.example.com/users" net.http.get
# Stack: ( Map ) where Map = { "status": 200, "body": "...", "ok": true }

"https://api.example.com/users" "{\"name\":\"Alice\"}" "application/json" net.http.post
# Stack: ( Map ) where Map = { "status": 201, "body": "...", "ok": true }

dup "ok" map.get if
  "body" map.get json.decode
else
  "error" map.get io.write-line
then

§Response Map

  • "status" (Int): HTTP status code, or 0 on connection-level error.
  • "body" (String): response body as raw bytes (byte-clean — binary downloads round-trip intact).
  • "ok" (Bool): true iff status is 2xx.
  • "error" (String): error message; present only on failure.

§Security: SSRF protection

Requests are blocked when the URL’s host resolves to a private, loopback, link-local (cloud metadata), or unique-local IP. The check uses the may-aware DNS layer (see crate::dns::resolve) and passes its resolved address list to the connect path, so there is exactly one getaddrinfo per request and it runs on a dedicated worker thread — never on a may carrier.

§v1 limitations

  • No redirect following: 3xx is returned to the caller as-is.
  • No automatic decompression: we send Accept-Encoding: identity. Use compress.gunzip etc. on the body if you ask for an encoded transfer manually.
  • No per-request timeout (a deadline pass is planned across all networking layers).
  • No client certificate authentication, ALPN selection, or peer-cert inspection — inherited from net.tls.client.
  • No header customisation beyond Content-Type (set automatically for POST/PUT).

Functions§

patch_seq_http_delete
HTTP DELETE. ( url -- response ).
patch_seq_http_get
HTTP GET. ( url -- response ).
patch_seq_http_post
HTTP POST. ( url body content-type -- response ).
patch_seq_http_put
HTTP PUT. ( url body content-type -- response ).