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

静态文件服务过滤器 更多...

#include <http_filter.hpp>

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

Public 成员函数

 static_file_filter (string root_path)
 构造函数
bool pre_filter (http_request &request, http_response &response) override
 预处理方法
void do_filter (http_request &request, http_response &response) override
 核心过滤方法
string name () const override
 获取过滤器名称
optional< http_contentget_mime_type (const string &path) const
 获取MIME类型
void add_mime_type (const string &extension, http_content content_type)
 添加MIME类型映射
void set_spa_fallback (string index_file)
 启用SPA回退模式
const stringspa_fallback () const noexcept
 查询SPA回退文件
bool is_spa_fallback_enabled () const noexcept
 查询SPA回退是否启用
void add_spa_exclude_path (string path_prefix)
 添加SPA回退排除路径
Public 成员函数 继承自 neforce::http::http_filter
virtual void post_filter (http_request &request, http_response &response)
 后处理方法

静态 Public 成员函数

static bool is_safe_path (const string &path)
 检查路径是否安全

详细描述

静态文件服务过滤器

提供静态文件服务功能,当请求匹配文件路径时返回文件内容。

在文件 http_filter.hpp237 行定义.

构造及析构函数说明

◆ static_file_filter()

neforce::http::static_file_filter::static_file_filter ( string root_path)
explicit

构造函数

参数
root_path文件根目录

成员函数说明

◆ add_mime_type()

void neforce::http::static_file_filter::add_mime_type ( const string & extension,
http_content content_type )

添加MIME类型映射

参数
extension文件扩展名
content_typeMIME类型

◆ add_spa_exclude_path()

void neforce::http::static_file_filter::add_spa_exclude_path ( string path_prefix)

添加SPA回退排除路径

参数
path_prefix路径前缀(如"/api")

以该前缀开头的请求不会被SPA回退处理,将传递给路由器。 用于保护API路由不被SPA回退拦截。

◆ do_filter()

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

核心过滤方法

参数
requestHTTP请求
responseHTTP响应

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

实现了 neforce::http::http_filter.

在文件 http_filter.hpp256 行定义.

◆ get_mime_type()

optional< http_content > neforce::http::static_file_filter::get_mime_type ( const string & path) const
nodiscard

获取MIME类型

参数
path文件路径
返回
MIME类型,未找到返回none

◆ is_safe_path()

bool neforce::http::static_file_filter::is_safe_path ( const string & path)
staticnodiscard

检查路径是否安全

参数
path文件路径
返回
安全返回true

防止路径遍历攻击,拒绝包含".."或"//"的路径。

◆ is_spa_fallback_enabled()

bool neforce::http::static_file_filter::is_spa_fallback_enabled ( ) const
inlinenodiscardnoexcept

查询SPA回退是否启用

返回
已启用返回true

在文件 http_filter.hpp302 行定义.

◆ name()

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

获取过滤器名称

返回
过滤器名称

重载 neforce::http::http_filter .

在文件 http_filter.hpp257 行定义.

◆ pre_filter()

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

预处理方法

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

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

重载 neforce::http::http_filter .

◆ set_spa_fallback()

void neforce::http::static_file_filter::set_spa_fallback ( string index_file)

启用SPA回退模式

参数
index_file回退文件路径(如"index.html")

当请求的路径不是已知静态文件时,返回指定的回退文件。 用于 Vue Router / React Router 的 history 模式。 传入空字符串可禁用SPA回退。

◆ spa_fallback()

const string & neforce::http::static_file_filter::spa_fallback ( ) const
inlinenodiscardnoexcept

查询SPA回退文件

返回
回退文件路径,空字符串表示未启用

在文件 http_filter.hpp296 行定义.


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