NexusForce 1.0.0
A rigorously engineered full-stack C++ backend library.
载入中...
搜索中...
未找到
neforce::http::http2_connection类 参考

HTTP/2 连接管理器 更多...

#include <http2_connection.hpp>

类 neforce::http::http2_connection 继承关系图:
[图例]

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_settingslocal_settings () noexcept
 获取本地设置
const http2_settingsremote_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 连接的生命周期:

  • Frame I/O(通过 tcp_socket)
  • HPACK 编码/解码
  • Stream 状态管理
  • Flow Control
  • http_router 集成

使用 io_context 驱动异步 I/O。 继承 enable_shared_from_this 以支持异步回调生命周期安全。

在文件 http2_connection.hpp46 行定义.

成员函数说明

◆ handle_upgrade_request()

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().

◆ send_push_promise()

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 拒绝。 必须在发送任何可能触发新资源请求的响应数据之前调用。

◆ send_response()

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是否结束流

◆ set_router()

void neforce::http::http2_connection::set_router ( http_router * router)
inline

设置路由器(启用自动请求分发)

设置后,收到 HTTP/2 请求时将自动转换为 http_request, 通过路由器分发,并将响应转回 HTTP/2 帧发送。

在文件 http2_connection.hpp182 行定义.

◆ start()

void neforce::http::http2_connection::start ( )

启动连接处理

发送初始 SETTINGS 帧并开始读取客户端帧。


该类的文档由以下文件生成: