XU XUv0.8.8
中文

API

#net/http2

import: #net/http2

counts: 7 fns, 5 methods, 5 types, 1 consts, 0 ifaces

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

XuAPI
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

struct Frame

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

Purpose

Public struct `Frame`.

Parameters

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

Public struct `Decoded`.

Parameters

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

struct Response

XuAPI
pub struct Response {
    pub status int
    pub body string
    pub ok bool
    pub err string
}

Purpose

Public struct `Response`.

Parameters

status int
field (int)
body string
body
ok bool
field (bool)
err string
error

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.

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.

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

parse_status extracts :status from a HEADERS payload.

Parameters

blk string
blk (string)

Returns

int — a value of this type

struct TcpClient

XuAPI
pub struct TcpClient {

}

Purpose

h2c over net.Conn

Parameters

none

dial_tcp

XuAPI
pub fn dial_tcp(addr string) TcpClient

Purpose

dial_tcp speaks prior-knowledge h2c (no TLS). Throws on failure.

Parameters

addr string
address (string)

Returns

TcpClient — a value of this type

(&mut TcpClient) get

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

Purpose

Get issues GET on a new stream and collects the body.

Parameters

t &mut TcpClient
receiver &mut TcpClient (exclusive borrow)
authority string
authority (string)
path string
filesystem path (string)

Returns

Response — a value of this type

(&mut TcpClient) close

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

Purpose

Method on `&mut TcpClient`: close the resource.

Parameters

t &mut TcpClient
receiver &mut TcpClient (exclusive borrow)

struct TlsClient

XuAPI
pub struct TlsClient {

}

Purpose

TLS client (ALPN h2)

Parameters

none

dial_tls

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

Purpose

dial_tls connects with ALPN h2 and performs the HTTP/2 preface. Throws on failure.

Parameters

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

Returns

TlsClient — a value of this type

(&mut TlsClient) get

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

Purpose

get issues GET over TLS.

Parameters

t &mut TlsClient
receiver &mut TlsClient (exclusive borrow)
authority string
authority (string)
path string
filesystem path (string)

Returns

Response — a value of this type

(&mut TlsClient) post

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

Purpose

post issues POST with a body (HEADERS then DATA+END_STREAM).

Parameters

t &mut TlsClient
receiver &mut TlsClient (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

(&mut TlsClient) close

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

Purpose

Method on `&mut TlsClient`: close the resource.

Parameters

t &mut TlsClient
receiver &mut TlsClient (exclusive borrow)