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

HTTP反向代理过滤器 更多...

#include <reverse_proxy.hpp>

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

Public 类型

using header_rewrite_cb = function<void(unordered_map<string, string>&)>
 请求头重写回调
using backend_selector_cb = function<proxy_backend(const http_request&)>
 后端选择回调

Public 成员函数

 reverse_proxy_filter (io_context &ctx)
 构造函数
 reverse_proxy_filter (io_context &ctx, string host, ports port, string scheme="http")
 构造函数(单后端)
void add_backend (proxy_backend backend)
 添加后端服务器
void set_path_prefix (string prefix)
 设置路径前缀匹配(仅代理匹配路径)
void set_backend_selector (backend_selector_cb selector)
 设置自定义后端选择器
void set_header_rewrite (header_rewrite_cb cb)
 设置请求头重写回调
void add_skip_response_header (string header)
 添加不透传的响应头
bool pre_filter (http_request &request, http_response &response) override
 预处理方法
void do_filter (http_request &request, http_response &response) override
 核心过滤方法
string name () const override
 获取过滤器名称
Public 成员函数 继承自 neforce::http::http_filter
virtual void post_filter (http_request &request, http_response &response)
 后处理方法

Public 属性

milliseconds connect_timeout {5000}
 连接超时(毫秒)
milliseconds send_timeout {5000}
 发送超时(毫秒)
milliseconds receive_timeout {30000}
 接收超时(毫秒)
bool follow_redirects {false}
 是否跟随重定向
bool passthrough_host_header {false}
 是否保持原始 Host 头(不过滤)

详细描述

HTTP反向代理过滤器

将匹配的请求转发到后端服务器,并将响应返回给客户端。 支持请求头重写、响应头过滤、超时控制。

使用示例:

proxy.add_backend({"api-backend", ports(8080)});
proxy.set_path_prefix("/api"); // 仅代理 /api/ * 路径
void add_backend(proxy_backend backend)
添加后端服务器
reverse_proxy_filter(io_context &ctx)
构造函数
void set_path_prefix(string prefix)
设置路径前缀匹配(仅代理匹配路径)
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result) noexcept(noexcept(inner::__move_aux(first, last, result)))
移动范围元素
constexpr unique_ptr< T > make_unique(Args &&... args)
创建unique_ptr
网络端口封装类

在文件 reverse_proxy.hpp52 行定义.

构造及析构函数说明

◆ reverse_proxy_filter() [1/2]

neforce::http::reverse_proxy_filter::reverse_proxy_filter ( io_context & ctx)
inlineexplicit

构造函数

参数
ctx异步 I/O 执行上下文

在文件 reverse_proxy.hpp74 行定义.

◆ reverse_proxy_filter() [2/2]

neforce::http::reverse_proxy_filter::reverse_proxy_filter ( io_context & ctx,
string host,
ports port,
string scheme = "http" )
inline

构造函数(单后端)

参数
ctx异步 I/O 执行上下文

在文件 reverse_proxy.hpp81 行定义.

引用了 add_backend() , 以及 neforce::move().

成员函数说明

◆ do_filter()

void neforce::http::reverse_proxy_filter::do_filter ( http_request & request,
http_response & response )
inlineoverridevirtual

核心过滤方法

参数
requestHTTP请求
responseHTTP响应

执行实际的过滤逻辑。通常由具体处理器实现, 中间件过滤器可能不实现此方法。

实现了 neforce::http::http_filter.

在文件 reverse_proxy.hpp127 行定义.

◆ name()

string neforce::http::reverse_proxy_filter::name ( ) const
inlinenodiscardoverridevirtual

获取过滤器名称

返回
过滤器名称

重载 neforce::http::http_filter .

在文件 reverse_proxy.hpp128 行定义.

◆ pre_filter()

bool neforce::http::reverse_proxy_filter::pre_filter ( http_request & request,
http_response & response )
overridevirtual

预处理方法

参数
requestHTTP请求
responseHTTP响应
返回
返回false表示中断后续处理

在请求处理前调用,可以检查请求、修改请求或提前返回响应。

重载 neforce::http::http_filter .


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