XU XUv0.16.0

#net/http2

import: #net/http2

counts: 10 functions, 9 methods, 7 types, 1 constants, 0 method sets

Minimal 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 PREFACE

XuAPI
pub const PREFACE = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"

Purpose

Constant PREFACE, defining protocol or algorithm parameters.

struct Frame

XuAPI
pub struct Frame {
    pub typ int
    pub flags int
    pub stream_id int
    pub payload string
}

Purpose

Http2 Protocol data frame encapsulation.

Public fields

typ int
field (int)
flags int
field (int)
stream_id int
field (int)
payload string
field (string)

struct Decoded

XuAPI
pub struct Decoded {
    pub f Frame
    pub need int
}

Purpose

Structure encapsulating f, need.

Public fields

f Frame
callback or format string
need int
field (int)

struct Header

XuAPI
pub struct Header {
    pub name string
    pub value string
}

Purpose

Http2 Metadata header descriptor structure.

Public fields

name string
name
value string
field (string)

struct Response

XuAPI
pub struct Response {
    pub status int
    pub body string
    pub headers []Header
    pub ok bool
    pub err string
}

Purpose

Http2 Server response payload containing status, headers, and body.

Public fields

status int
field (int)
body string
body
headers []Header
field ([]Header)
ok bool
field (bool)
err string
error

(Response) header

XuAPI
pub fn (r Response) header(name string) string

Purpose

Execute header on Response.

Parameters

r Response
The Response instance used by this call (value receiver).
name string
name (string)

Returns

string — result string

encode_frame

XuAPI
pub fn encode_frame(typ int, flags int, sid int, payload string) string

Purpose

encode_frame builds a raw HTTP/2 frame.

Parameters

typ int
typ (int)
flags int
flags (int)
sid int
sid (int)
payload string
payload (string)

Returns

string — result string

decode_frame

XuAPI
pub fn decode_frame(buf string) Decoded

Purpose

decode_frame parses one frame. need=0 when buf is short.

Parameters

buf string
buffer (string)

Returns

Decoded — a value of this type

encode_get_headers

XuAPI
pub fn encode_get_headers(authority string, path string) string

Purpose

encode_get_headers builds a HEADERS payload for GET (:scheme https). Throws on failure; handle the error or propagate it to the caller.

Parameters

authority string
authority (string)
path string
filesystem path (string)

Returns

string — result string

encode_post_headers

XuAPI
pub fn encode_post_headers(authority string, path string, content_type string, authorization string) string

Purpose

encode_post_headers builds HEADERS for POST with content-type + optional bearer. Throws on failure; handle the error or propagate it to the caller.

Parameters

authority string
authority (string)
path string
filesystem path (string)
content_type string
content_type (string)
authorization string
authorization (string)

Returns

string — result string

parse_status

XuAPI
pub fn parse_status(blk string) int

Purpose

Unsupported or malformed blocks have no usable status in this compatibility API.

Parameters

blk string
blk (string)

Returns

int — a value of this type

struct ClientConfig

XuAPI
pub struct ClientConfig {
    pub dial_timeout_ns int
    pub io_timeout_ns int
}

Purpose

Http2 Configuration parameters and options set.

Public fields

dial_timeout_ns int
field (int)
io_timeout_ns int
field (int)

default_client_config

XuAPI
pub fn default_client_config() ClientConfig

Purpose

Default client config.

Parameters

No arguments are required.

Returns

ClientConfig — a value of this type

struct TcpClient

XuAPI
pub struct TcpClient {
    pub timeout_ns int
}

Purpose

Http2 Client session maintaining connection and operations.

Public fields

timeout_ns int
timeout in nanoseconds

struct TlsClient

XuAPI
pub struct TlsClient {
    pub timeout_ns int
}

Purpose

Http2 Client session maintaining connection and operations.

Public fields

timeout_ns int
timeout in nanoseconds

($&TcpClient) set_timeout

XuAPI
pub fn (t $&TcpClient) set_timeout(ns int)

Purpose

Operation on $&TcpClient: set timeout.

Parameters

t $&TcpClient
The TcpClient instance used by this call (exclusive borrow).
ns int
ns (int)

Returns

This call does not return a value.

($&TlsClient) set_timeout

XuAPI
pub fn (t $&TlsClient) set_timeout(ns int)

Purpose

Operation on $&TlsClient: set timeout.

Parameters

t $&TlsClient
The TlsClient instance used by this call (exclusive borrow).
ns int
ns (int)

Returns

This call does not return a value.

dial_tcp_config

XuAPI
pub fn dial_tcp_config(addr string, cfg ClientConfig) TcpClient

Purpose

dial_tcp_config speaks prior-knowledge h2c with explicit timeout config. Throws on failure; handle the error or propagate it to the caller.

Parameters

addr string
address (string)
cfg ClientConfig
cfg (ClientConfig)

Returns

TcpClient — a value of this type

dial_tcp

XuAPI
pub fn dial_tcp(addr string) TcpClient

Purpose

dial_tcp speaks prior-knowledge h2c. Failed prefaces close the connection. Throws on failure; handle the error or propagate it to the caller.

Parameters

addr string
address (string)

Returns

TcpClient — a value of this type

dial_tls_config

XuAPI
pub fn dial_tls_config(addr string, server_name string, cfg ClientConfig) TlsClient

Purpose

dial_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.

Parameters

addr string
address (string)
server_name string
server_name (string)
cfg ClientConfig
cfg (ClientConfig)

Returns

TlsClient — a value of this type

dial_tls

XuAPI
pub fn dial_tls(addr string, server_name string) TlsClient

Purpose

dial_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.

Parameters

addr string
address (string)
server_name string
server_name (string)

Returns

TlsClient — a value of this type

($&TcpClient) get

XuAPI
pub fn (t $&TcpClient) get(authority string, path string) Response

Purpose

Success requires a complete current stream. Failures preserve received data for diagnostics and retire the connection; partial responses are never reused.

Parameters

t $&TcpClient
The TcpClient instance used by this call (exclusive borrow).
authority string
authority (string)
path string
filesystem path (string)

Returns

Response — a value of this type

($&TlsClient) get

XuAPI
pub fn (t $&TlsClient) get(authority string, path string) Response

Purpose

Execute get on $&TlsClient.

Parameters

t $&TlsClient
The TlsClient instance used by this call (exclusive borrow).
authority string
authority (string)
path string
filesystem path (string)

Returns

Response — a value of this type

($&TlsClient) post

XuAPI
pub fn (t $&TlsClient) post(authority string, path string, content_type string, authorization string, body string) Response

Purpose

POST remains the single-DATA-frame subset; oversized requests fail explicitly.

Parameters

t $&TlsClient
The TlsClient instance used by this call (exclusive borrow).
authority string
authority (string)
path string
filesystem path (string)
content_type string
content_type (string)
authorization string
authorization (string)
body string
body (string)

Returns

Response — a value of this type

($&TlsClient) post_with_headers

XuAPI
pub fn (t $&TlsClient) post_with_headers(authority string, path string, content_type string, authorization string, extra_names []string, extra_vals []string, body string) Response

Purpose

Operation on $&TlsClient: post with headers.

Parameters

t $&TlsClient
The TlsClient instance used by this call (exclusive borrow).
authority string
authority (string)
path string
filesystem path (string)
content_type string
content_type (string)
authorization string
authorization (string)
extra_names []string
extra_names ([]string)
extra_vals []string
extra_vals ([]string)
body string
body (string)

Returns

Response — a value of this type

($&TcpClient) close

XuAPI
pub fn (t $&TcpClient) close()

Purpose

Operation on $&TcpClient: close the resource.

Parameters

t $&TcpClient
The TcpClient instance used by this call (exclusive borrow).

Returns

This call does not return a value.

($&TlsClient) close

XuAPI
pub fn (t $&TlsClient) close()

Purpose

Operation on $&TlsClient: close the resource.

Parameters

t $&TlsClient
The TlsClient instance used by this call (exclusive borrow).

Returns

This call does not return a value.