XU XUv0.16.0

#net/http2

导入方式: #net/http2

公开 API: 10 函数, 9 方法, 7 类型, 1 常量, 0 方法集

标准库包 `#net/http2`。

const PREFACE

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

用途

常量 PREFACE,定义了相关的协议或算法配置参数。

struct Frame

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

用途

Http2 协议数据帧结构封装。

公开字段

typ int
字段(int)
flags int
字段(int)
stream_id int
字段(int)
payload string
字段(string)

struct Decoded

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

用途

承载 f、need 等属性的结构体。

公开字段

f Frame
回调或格式串
need int
字段(int)

struct Header

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

用途

Http2 元信息头部描述结构。

公开字段

name string
名字
value string
字段(string)

struct Response

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

用途

Http2 服务端响应结果,包含状态码、响应头与正文数据。

公开字段

status int
字段(int)
body string
正文
headers []Header
字段([]Header)
ok bool
字段(bool)
err string
错误

(Response) header

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

用途

Response 上的操作:头。

参数

r Response
本次调用使用的 Response 实例;按值接收。
name string
名字(string)

返回值

string — 结果字符串

encode_frame

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

用途

编码 frame 数据。

参数

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

返回值

string — 结果字符串

decode_frame

XuAPI
pub fn decode_frame(buf string) Decoded

用途

解码 frame 数据。

参数

buf string
缓冲(string)

返回值

Decoded — 该类型的值

encode_get_headers

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

用途

编码 get headers 数据。失败时抛出错误,调用方需处理或继续传播。

参数

authority string
authority(string)
path string
文件系统路径(string)

返回值

string — 结果字符串

encode_post_headers

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

用途

编码 post headers 数据。失败时抛出错误,调用方需处理或继续传播。

参数

authority string
authority(string)
path string
文件系统路径(string)
content_type string
content_type(string)
authorization string
authorization(string)

返回值

string — 结果字符串

parse_status

XuAPI
pub fn parse_status(blk string) int

用途

解析为 status。

参数

blk string
blk(string)

返回值

int — 该类型的值

struct ClientConfig

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

用途

Http2 配置参数与选项集合。

公开字段

dial_timeout_ns int
字段(int)
io_timeout_ns int
字段(int)

default_client_config

XuAPI
pub fn default_client_config() ClientConfig

用途

执行 default client config 操作。

参数

无需传入参数。

返回值

ClientConfig — 该类型的值

struct TcpClient

XuAPI
pub struct TcpClient {
    pub timeout_ns int
}

用途

Http2 客户端会话实例,维护与服务端的连接并提供操作接口。

公开字段

timeout_ns int
超时(纳秒)

struct TlsClient

XuAPI
pub struct TlsClient {
    pub timeout_ns int
}

用途

Http2 客户端会话实例,维护与服务端的连接并提供操作接口。

公开字段

timeout_ns int
超时(纳秒)

($&TcpClient) set_timeout

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

用途

$&TcpClient 上的操作:设置 timeout。

参数

t $&TcpClient
本次调用使用的 TcpClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
ns int
ns(int)

返回值

不返回值。

($&TlsClient) set_timeout

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

用途

$&TlsClient 上的操作:设置 timeout。

参数

t $&TlsClient
本次调用使用的 TlsClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
ns int
ns(int)

返回值

不返回值。

dial_tcp_config

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

用途

执行 dial tcp config 操作。失败时抛出错误,调用方需处理或继续传播。

参数

addr string
地址(string)
cfg ClientConfig
cfg(ClientConfig)

返回值

TcpClient — 该类型的值

dial_tcp

XuAPI
pub fn dial_tcp(addr string) TcpClient

用途

拨 TCP。失败时抛出错误,调用方需处理或继续传播。

参数

addr string
地址(string)

返回值

TcpClient — 该类型的值

dial_tls_config

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

用途

执行 dial tls config 操作。失败时抛出错误,调用方需处理或继续传播。

参数

addr string
地址(string)
server_name string
server_name(string)
cfg ClientConfig
cfg(ClientConfig)

返回值

TlsClient — 该类型的值

dial_tls

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

用途

执行 dial tls 操作。失败时抛出错误,调用方需处理或继续传播。

参数

addr string
地址(string)
server_name string
server_name(string)

返回值

TlsClient — 该类型的值

($&TcpClient) get

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

用途

在 $&TcpClient 上执行 get 操作。

参数

t $&TcpClient
本次调用使用的 TcpClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
authority string
authority(string)
path string
文件系统路径(string)

返回值

Response — 该类型的值

($&TlsClient) get

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

用途

在 $&TlsClient 上执行 get 操作。

参数

t $&TlsClient
本次调用使用的 TlsClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
authority string
authority(string)
path string
文件系统路径(string)

返回值

Response — 该类型的值

($&TlsClient) post

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

用途

在 $&TlsClient 上执行 post 操作。

参数

t $&TlsClient
本次调用使用的 TlsClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
authority string
authority(string)
path string
文件系统路径(string)
content_type string
content_type(string)
authorization string
authorization(string)
body string
正文(string)

返回值

Response — 该类型的值

($&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

用途

$&TlsClient 上的操作:执行 post with headers 操作。

参数

t $&TlsClient
本次调用使用的 TlsClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。
authority string
authority(string)
path string
文件系统路径(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
正文(string)

返回值

Response — 该类型的值

($&TcpClient) close

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

用途

$&TcpClient 上的操作:关闭资源。

参数

t $&TcpClient
本次调用使用的 TcpClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

不返回值。

($&TlsClient) close

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

用途

$&TlsClient 上的操作:关闭资源。

参数

t $&TlsClient
本次调用使用的 TlsClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。

返回值

不返回值。