|
NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
|
HTTP/2 连接管理器 更多...
#include <http2_connection.hpp>
Public 成员函数 | |
| void | start () |
| 启动连接处理 | |
| void | send_response (uint32_t stream_id, const vector< hpack_header_field > &headers, const string &body={}, bool end_stream=true) |
| 发送 HTTP 响应(HEADERS + DATA) | |
| void | send_push_promise (uint32_t stream_id, uint32_t promised_stream_id, const vector< hpack_header_field > &request_headers) |
| 发送 PUSH_PROMISE(Server Push) | |
| void | send_rst_stream (uint32_t stream_id, http2_error error) |
| 发送 RST_STREAM | |
| void | send_goaway (http2_error error=http2_error::NO_ERROR) |
| 发送 GOAWAY 并关闭连接 | |
| void | handle_upgrade_request (uint32_t stream_id, const vector< hpack_header_field > &headers, const byte_t *data, size_t data_len, bool end_stream) |
| h2c 升级请求注入(RFC 7540 §3.2) | |
| void | set_stream_handler (stream_handler handler) |
| 设置流处理器(收到完整请求时回调) | |
| void | set_router (http_router *router) |
| 设置路由器(启用自动请求分发) | |
| void | set_close_handler (close_handler handler) |
| 设置关闭回调 | |
| http2_settings & | local_settings () noexcept |
| 获取本地设置 | |
| const http2_settings & | remote_settings () const noexcept |
| 获取远程设置 | |
| Public 成员函数 继承自 neforce::enable_shared_from_this< http2_connection > | |
| shared_ptr< http2_connection > | shared_from_this () |
| 获取指向自身的共享指针 | |
| weak_ptr< http2_connection > | weak_from_this () noexcept |
| 获取指向 this 的弱指针 | |
额外继承的成员函数 | |
| Protected 成员函数 继承自 neforce::enable_shared_from_this< http2_connection > | |
| enable_shared_from_this () noexcept=default | |
| 构造函数 | |
HTTP/2 连接管理器
管理单个 HTTP/2 连接的生命周期:
使用 io_context 驱动异步 I/O。 继承 enable_shared_from_this 以支持异步回调生命周期安全。
在文件 http2_connection.hpp 第 46 行定义.
| void neforce::http::http2_connection::handle_upgrade_request | ( | uint32_t | stream_id, |
| const vector< hpack_header_field > & | headers, | ||
| const byte_t * | data, | ||
| size_t | data_len, | ||
| bool | end_stream ) |
h2c 升级请求注入(RFC 7540 §3.2)
将 HTTP/1.1 Upgrade 前的原始请求作为 HTTP/2 stream 1 注入路由器。 必须在 start() 之后、事件循环启动前调用。
引用了 neforce::data().
| void neforce::http::http2_connection::send_push_promise | ( | uint32_t | stream_id, |
| uint32_t | promised_stream_id, | ||
| const vector< hpack_header_field > & | request_headers ) |
发送 PUSH_PROMISE(Server Push)
| stream_id | 父流ID |
| promised_stream_id | 新承诺的流ID(必须为偶数,服务器发起) |
| request_headers | 承诺的请求头部 |
向客户端承诺将推送指定资源,客户端可以选择接受或通过 RST_STREAM 拒绝。 必须在发送任何可能触发新资源请求的响应数据之前调用。
| void neforce::http::http2_connection::send_response | ( | uint32_t | stream_id, |
| const vector< hpack_header_field > & | headers, | ||
| const string & | body = {}, | ||
| bool | end_stream = true ) |
发送 HTTP 响应(HEADERS + DATA)
| stream_id | 流ID |
| headers | 响应头部 |
| body | 响应体(可选) |
| end_stream | 是否结束流 |
|
inline |
设置路由器(启用自动请求分发)
设置后,收到 HTTP/2 请求时将自动转换为 http_request, 通过路由器分发,并将响应转回 HTTP/2 帧发送。
在文件 http2_connection.hpp 第 182 行定义.
| void neforce::http::http2_connection::start | ( | ) |
启动连接处理
发送初始 SETTINGS 帧并开始读取客户端帧。