const preface
pub const preface = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"Purpose
Public constant `preface`. Value `"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"`.
Parameters
none
API
#net/http2Minimal HTTP/2 client (RFC 7540 / HPACK RFC 7541 subset). v1 * frame codec (encode_frame / decode_frame) * GET headers HPACK (static table + raw literals, no Huffman) * h2c TcpClient (prior knowledge) * TlsClient via dial_tls (ClientHello ALPN offers h2 + http/1.1) Throw note: method may-throw is matched by caller-module name only (check_06_throw.ast_method_call_propagates_throw), so `conn.read` from net.http2 does not see tls.Conn.read's throw. tls_read_exact therefore absorbs errors with `or (err) { << got }` instead of `or >>`. Not in v1: POST/DATA out, HPACK Huffman, dynamic table, flow control, GOAWAY retry, server push.
const prefacepub const preface = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"Public constant `preface`. Value `"PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"`.
none
struct Framepub struct Frame {
pub typ int
pub flags int
pub stream_id int
pub payload string
}Public struct `Frame`.
typ intflags intstream_id intpayload stringstruct Decodedpub struct Decoded {
pub f Frame
pub need int
}Public struct `Decoded`.
f Frameneed intstruct Responsepub struct Response {
pub status int
pub body string
pub ok bool
pub err string
}Public struct `Response`.
status intbody stringok boolerr stringencode_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.
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.
authority stringpath stringcontent_type stringauthorization stringstring — result string
parse_statuspub fn parse_status(blk string) intparse_status extracts :status from a HEADERS payload.
blk stringint — a value of this type
struct TcpClientpub struct TcpClient {
}h2c over net.Conn
none
dial_tcppub fn dial_tcp(addr string) TcpClientdial_tcp speaks prior-knowledge h2c (no TLS). Throws on failure.
addr stringTcpClient — a value of this type
(&mut TcpClient) getpub fn (t &mut TcpClient) get(authority string, path string) ResponseGet issues GET on a new stream and collects the body.
t &mut TcpClientauthority stringpath stringResponse — a value of this type
(&mut TcpClient) closepub fn (t &mut TcpClient) close()Method on `&mut TcpClient`: close the resource.
t &mut TcpClientstruct TlsClientpub struct TlsClient {
}TLS client (ALPN h2)
none
dial_tlspub fn dial_tls(addr string, server_name string) TlsClientdial_tls connects with ALPN h2 and performs the HTTP/2 preface. Throws on failure.
addr stringserver_name stringTlsClient — a value of this type
(&mut TlsClient) getpub fn (t &mut TlsClient) get(authority string, path string) Responseget issues GET over TLS.
t &mut TlsClientauthority stringpath stringResponse — a value of this type
(&mut TlsClient) postpub fn (t &mut TlsClient) post(authority string, path string, content_type string, authorization string, body string) Responsepost issues POST with a body (HEADERS then DATA+END_STREAM).
t &mut TlsClientauthority stringpath stringcontent_type stringauthorization stringbody stringResponse — a value of this type
(&mut TlsClient) closepub fn (t &mut TlsClient) close()Method on `&mut TlsClient`: close the resource.
t &mut TlsClient