ilusm.dev

http2

HTTP/2 client surface - open a multiplexed connection to an HTTP/2 server, issue requests with any method, path, headers, and body, then close the connection. Delegates to embedder-provided __http2_* host natives.

Load with: use http2

What this module does

http2 provides a minimal HTTP/2 client surface. The actual wire protocol (ALPN negotiation, HPACK header compression, stream multiplexing) is handled by the embedder's __http2_* native functions. This module documents the intended interface and provides thin wrappers with sensible defaults for the options and headers arguments.

Quick example

use http2

# Connect
c = h2cln("https://api.example.com", nil)

# GET request
r = h2req(c, "GET", "/users", nil, nil)

# POST with headers and body
r2 = h2req(c, "POST", "/users",
    {"Content-Type": "application/json"},
    jsn.enc({name: "alice"}))

# Close
h2cls(c)

Functions

Connection

h2cln(url, opts)

Opens an HTTP/2 connection to url. opts is an options object or nil for defaults. Returns a connection handle passed to h2req and h2cls.

h2cls(conn)

Closes the HTTP/2 connection and releases its resources.

Requests

h2req(conn, method, path, headers, body)

Issues an HTTP/2 request on the connection. headers defaults to {} if nil. body may be nil for GET/HEAD. Returns the response from the host native.

Notes

  • Availability depends on the embedder - the host stub must implement __http2_connect, __http2_close, and __http2_request.
  • No stdlib dependencies.