静态文件服务过滤器
更多...
#include <http_filter.hpp>
静态文件服务过滤器
提供静态文件服务功能,当请求匹配文件路径时返回文件内容。
在文件 http_filter.hpp 第 237 行定义.
◆ static_file_filter()
| neforce::http::static_file_filter::static_file_filter |
( |
string | root_path | ) |
|
|
explicit |
◆ add_mime_type()
| void neforce::http::static_file_filter::add_mime_type |
( |
const string & | extension, |
|
|
http_content | content_type ) |
添加MIME类型映射
- 参数
-
| extension | 文件扩展名 |
| content_type | MIME类型 |
◆ add_spa_exclude_path()
| void neforce::http::static_file_filter::add_spa_exclude_path |
( |
string | path_prefix | ) |
|
添加SPA回退排除路径
- 参数
-
以该前缀开头的请求不会被SPA回退处理,将传递给路由器。 用于保护API路由不被SPA回退拦截。
◆ do_filter()
◆ get_mime_type()
获取MIME类型
- 参数
-
- 返回
- MIME类型,未找到返回none
◆ is_safe_path()
| bool neforce::http::static_file_filter::is_safe_path |
( |
const string & | path | ) |
|
|
staticnodiscard |
检查路径是否安全
- 参数
-
- 返回
- 安全返回true
防止路径遍历攻击,拒绝包含".."或"//"的路径。
◆ is_spa_fallback_enabled()
| bool neforce::http::static_file_filter::is_spa_fallback_enabled |
( |
| ) |
const |
|
inlinenodiscardnoexcept |
◆ name()
| string neforce::http::static_file_filter::name |
( |
| ) |
const |
|
inlinenodiscardoverridevirtual |
◆ pre_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 |
该类的文档由以下文件生成: