const PREFACE
pub const PREFACE = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"用途
常量 PREFACE,定义了相关的协议或算法配置参数。
#net/http2标准库包 `#net/http2`。
const PREFACEpub const PREFACE = "PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n"常量 PREFACE,定义了相关的协议或算法配置参数。
struct Framepub struct Frame {
pub typ int
pub flags int
pub stream_id int
pub payload string
}Http2 协议数据帧结构封装。
typ intflags intstream_id intpayload stringstruct Decodedpub struct Decoded {
pub f Frame
pub need int
}承载 f、need 等属性的结构体。
f Frameneed intstruct Headerpub struct Header {
pub name string
pub value string
}Http2 元信息头部描述结构。
name stringvalue stringstruct Responsepub struct Response {
pub status int
pub body string
pub headers []Header
pub ok bool
pub err string
}Http2 服务端响应结果,包含状态码、响应头与正文数据。
status intbody stringheaders []Headerok boolerr string(Response) headerpub fn (r Response) header(name string) stringResponse 上的操作:头。
r ResponseResponse 实例;按值接收。name stringstring — 结果字符串
encode_framepub fn encode_frame(typ int, flags int, sid int, payload string) string编码 frame 数据。
typ intflags intsid intpayload stringstring — 结果字符串
decode_framepub fn decode_frame(buf string) Decoded解码 frame 数据。
buf stringDecoded — 该类型的值
encode_get_headerspub fn encode_get_headers(authority string, path string) string编码 get headers 数据。失败时抛出错误,调用方需处理或继续传播。
authority stringpath stringstring — 结果字符串
encode_post_headerspub fn encode_post_headers(authority string, path string, content_type string, authorization string) string编码 post headers 数据。失败时抛出错误,调用方需处理或继续传播。
authority stringpath stringcontent_type stringauthorization stringstring — 结果字符串
parse_statuspub fn parse_status(blk string) int解析为 status。
blk stringint — 该类型的值
struct ClientConfigpub struct ClientConfig {
pub dial_timeout_ns int
pub io_timeout_ns int
}Http2 配置参数与选项集合。
dial_timeout_ns intio_timeout_ns intdefault_client_configpub fn default_client_config() ClientConfig执行 default client config 操作。
无需传入参数。
ClientConfig — 该类型的值
struct TcpClientpub struct TcpClient {
pub timeout_ns int
}Http2 客户端会话实例,维护与服务端的连接并提供操作接口。
timeout_ns intstruct TlsClientpub struct TlsClient {
pub timeout_ns int
}Http2 客户端会话实例,维护与服务端的连接并提供操作接口。
timeout_ns int($&TcpClient) set_timeoutpub fn (t $&TcpClient) set_timeout(ns int)$&TcpClient 上的操作:设置 timeout。
t $&TcpClientTcpClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。ns int不返回值。
($&TlsClient) set_timeoutpub fn (t $&TlsClient) set_timeout(ns int)$&TlsClient 上的操作:设置 timeout。
t $&TlsClientTlsClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。ns int不返回值。
dial_tcp_configpub fn dial_tcp_config(addr string, cfg ClientConfig) TcpClient执行 dial tcp config 操作。失败时抛出错误,调用方需处理或继续传播。
addr stringcfg ClientConfigTcpClient — 该类型的值
dial_tcppub fn dial_tcp(addr string) TcpClient拨 TCP。失败时抛出错误,调用方需处理或继续传播。
addr stringTcpClient — 该类型的值
dial_tls_configpub fn dial_tls_config(addr string, server_name string, cfg ClientConfig) TlsClient执行 dial tls config 操作。失败时抛出错误,调用方需处理或继续传播。
addr stringserver_name stringcfg ClientConfigTlsClient — 该类型的值
dial_tlspub fn dial_tls(addr string, server_name string) TlsClient执行 dial tls 操作。失败时抛出错误,调用方需处理或继续传播。
addr stringserver_name stringTlsClient — 该类型的值
($&TcpClient) getpub fn (t $&TcpClient) get(authority string, path string) Response在 $&TcpClient 上执行 get 操作。
t $&TcpClientTcpClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。authority stringpath stringResponse — 该类型的值
($&TlsClient) getpub fn (t $&TlsClient) get(authority string, path string) Response在 $&TlsClient 上执行 get 操作。
t $&TlsClientTlsClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。authority stringpath stringResponse — 该类型的值
($&TlsClient) postpub fn (t $&TlsClient) post(authority string, path string, content_type string, authorization string, body string) Response在 $&TlsClient 上执行 post 操作。
t $&TlsClientTlsClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。authority stringpath stringcontent_type stringauthorization stringbody stringResponse — 该类型的值
($&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) Response$&TlsClient 上的操作:执行 post with headers 操作。
t $&TlsClientTlsClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。authority stringpath stringcontent_type stringauthorization stringextra_names []stringextra_vals []stringbody stringResponse — 该类型的值
($&TcpClient) closepub fn (t $&TcpClient) close()$&TcpClient 上的操作:关闭资源。
t $&TcpClientTcpClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。不返回值。
($&TlsClient) closepub fn (t $&TlsClient) close()$&TlsClient 上的操作:关闭资源。
t $&TlsClientTlsClient 实例;以独占借用传入,方法可修改它,调用方仍持有实例。不返回值。