const PREFACE
pub const PREFACE = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"Purpose
Constant PREFACE, defining protocol or algorithm parameters.
#net/http2Minimal HTTP/2 client (RFC 9113 / HPACK RFC 7541 subset). v1 * frame codec (encode_frame / decode_frame) * GET headers HPACK (static table + raw and Huffman literals) * h2c TcpClient (prior knowledge) * TlsClient via dial_tls (ClientHello ALPN offers h2 + http/1.1) TCP and TLS share completion and field-block validation. Responses are limited to 4096 received frames, 64 KiB field blocks and 16 MiB bodies the advertised incoming frame limit remains 16 KiB. Limit exhaustion and transport/protocol failure close the connection and return ok=false. Still excluded: HPACK dynamic indexes, flow control, GOAWAY retry and server push. TLS POST supports one DATA frame of at most 16 KiB. Default timeout in nanoseconds for an HTTP/2 TLS connection.
const PREFACEpub const PREFACE = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"Constant PREFACE, defining protocol or algorithm parameters.
struct Framepub struct Frame {
pub typ int
pub flags int
pub stream_id int
pub payload string
}Http2 Protocol data frame encapsulation.
typ intflags intstream_id intpayload stringstruct Decodedpub struct Decoded {
pub f Frame
pub need int
}Structure encapsulating f, need.
f Frameneed intstruct Headerpub struct Header {
pub name string
pub value string
}Http2 Metadata header descriptor structure.
name stringvalue stringstruct Responsepub struct Response {
pub status int
pub body string
pub headers []Header
pub ok bool
pub err string
}Http2 Server response payload containing status, headers, and body.
status intbody stringheaders []Headerok boolerr string(Response) headerpub fn (r Response) header(name string) stringExecute header on Response.
r ResponseResponse instance used by this call (value receiver).name stringstring — result string
encode_framepub fn encode_frame(typ int, flags int, sid int, payload string) stringencode_frame builds a raw HTTP/2 frame.
typ intflags intsid intpayload stringstring — result string
decode_framepub fn decode_frame(buf string) Decodeddecode_frame parses one frame. need=0 when buf is short.
buf stringDecoded — a value of this type
encode_get_headerspub fn encode_get_headers(authority string, path string) stringencode_get_headers builds a HEADERS payload for GET (:scheme https). Throws on failure; handle the error or propagate it to the caller.
authority stringpath stringstring — result string
encode_post_headerspub fn encode_post_headers(authority string, path string, content_type string, authorization string) stringencode_post_headers builds HEADERS for POST with content-type + optional bearer. Throws on failure; handle the error or propagate it to the caller.
authority stringpath stringcontent_type stringauthorization stringstring — result string
parse_statuspub fn parse_status(blk string) intUnsupported or malformed blocks have no usable status in this compatibility API.
blk stringint — a value of this type
struct ClientConfigpub struct ClientConfig {
pub dial_timeout_ns int
pub io_timeout_ns int
}Http2 Configuration parameters and options set.
dial_timeout_ns intio_timeout_ns intdefault_client_configpub fn default_client_config() ClientConfigDefault client config.
No arguments are required.
ClientConfig — a value of this type
struct TcpClientpub struct TcpClient {
pub timeout_ns int
}Http2 Client session maintaining connection and operations.
timeout_ns intstruct TlsClientpub struct TlsClient {
pub timeout_ns int
}Http2 Client session maintaining connection and operations.
timeout_ns int($&TcpClient) set_timeoutpub fn (t $&TcpClient) set_timeout(ns int)Operation on $&TcpClient: set timeout.
t $&TcpClientTcpClient instance used by this call (exclusive borrow).ns intThis call does not return a value.
($&TlsClient) set_timeoutpub fn (t $&TlsClient) set_timeout(ns int)Operation on $&TlsClient: set timeout.
t $&TlsClientTlsClient instance used by this call (exclusive borrow).ns intThis call does not return a value.
dial_tcp_configpub fn dial_tcp_config(addr string, cfg ClientConfig) TcpClientdial_tcp_config speaks prior-knowledge h2c with explicit timeout config. Throws on failure; handle the error or propagate it to the caller.
addr stringcfg ClientConfigTcpClient — a value of this type
dial_tcppub fn dial_tcp(addr string) TcpClientdial_tcp speaks prior-knowledge h2c. Failed prefaces close the connection. Throws on failure; handle the error or propagate it to the caller.
addr stringTcpClient — a value of this type
dial_tls_configpub fn dial_tls_config(addr string, server_name string, cfg ClientConfig) TlsClientdial_tls_config verifies the peer, requires h2 ALPN, and completes the HTTP/2 preface. Throws on failure; handle the error or propagate it to the caller.
addr stringserver_name stringcfg ClientConfigTlsClient — a value of this type
dial_tlspub fn dial_tls(addr string, server_name string) TlsClientdial_tls verifies the peer, offers h2 ALPN and completes the HTTP/2 preface. Throws on failure; handle the error or propagate it to the caller.
addr stringserver_name stringTlsClient — a value of this type
($&TcpClient) getpub fn (t $&TcpClient) get(authority string, path string) ResponseSuccess requires a complete current stream. Failures preserve received data for diagnostics and retire the connection; partial responses are never reused.
t $&TcpClientTcpClient instance used by this call (exclusive borrow).authority stringpath stringResponse — a value of this type
($&TlsClient) getpub fn (t $&TlsClient) get(authority string, path string) ResponseExecute get on $&TlsClient.
t $&TlsClientTlsClient instance used by this call (exclusive borrow).authority stringpath stringResponse — a value of this type
($&TlsClient) postpub fn (t $&TlsClient) post(authority string, path string, content_type string, authorization string, body string) ResponsePOST remains the single-DATA-frame subset; oversized requests fail explicitly.
t $&TlsClientTlsClient instance used by this call (exclusive borrow).authority stringpath stringcontent_type stringauthorization stringbody stringResponse — a value of this type
($&TlsClient) post_with_headerspub fn (t $&TlsClient) post_with_headers(authority string, path string, content_type string, authorization string, extra_names []string, extra_vals []string, body string) ResponseOperation on $&TlsClient: post with headers.
t $&TlsClientTlsClient instance used by this call (exclusive borrow).authority stringpath stringcontent_type stringauthorization stringextra_names []stringextra_vals []stringbody stringResponse — a value of this type
($&TcpClient) closepub fn (t $&TcpClient) close()Operation on $&TcpClient: close the resource.
t $&TcpClientTcpClient instance used by this call (exclusive borrow).This call does not return a value.
($&TlsClient) closepub fn (t $&TlsClient) close()Operation on $&TlsClient: close the resource.
t $&TlsClientTlsClient instance used by this call (exclusive borrow).This call does not return a value.