1#ifndef NEFORCE_NETWORK_HTTP_HTTP_ROUTER_HPP__
2#define NEFORCE_NETWORK_HTTP_HTTP_ROUTER_HPP__
15NEFORCE_BEGIN_NAMESPACE__
89 bool is_regex =
false;
96 http_handler_t not_found_handler_;
97 http_handler_t method_not_allowed_handler_;
98 exception_handler_t exception_handler_;
112 void setup_default_handlers();
196 method_not_allowed_handler_ = _NEFORCE
move(handler);
263NEFORCE_END_NAMESPACE__
void handle_request_async(http_request request, function< void(http_response)> cb)
异步处理HTTP请求(回调模式)
void post(const string &path, http_handler_t handler)
POST请求
void set_exception_handler(exception_handler_t handler)
设置异常处理器
size_t route_count() const noexcept
获取路由总数
void set_method_not_allowed_handler(http_handler_t handler)
设置405处理器
void head(const string &path, http_handler_t handler)
HEAD请求
void clear_routes() noexcept
清空所有路由
void post_delete(const string &path, http_handler_t handler)
同时注册POST和DELETE
void get(const string &path, http_handler_t handler)
GET请求
bool strict_routing
是否严格匹配尾部斜杠
function< void(http_request &, http_response &, const exception &)> exception_handler_t
异常处理器类型
function< void(http_request &, http_response &)> http_handler_t
HTTP处理器类型
void all(const string &path, http_handler_t handler)
注册所有HTTP方法
void patch(const string &path, http_handler_t handler)
PATCH请求
http_response handle_request(http_request &request)
处理HTTP请求
bool has_route(const http_method &method, const string &path) const
检查是否存在指定路由
void put(const string &path, http_handler_t handler)
PUT请求
void connect(const string &path, http_handler_t handler)
CONNECT请求
void del(const string &path, http_handler_t handler)
DELETE请求
http_filter_chain & middleware_chain() noexcept
获取中间件链引用
void trace(const string &path, http_handler_t handler)
TRACE请求
void set_not_found_handler(http_handler_t handler)
设置404处理器
void route(const http_method &method, const string &path, const http_handler_t &handler)
通用路由注册
bool case_sensitive
是否大小写敏感
void options(const string &path, http_handler_t handler)
OPTIONS请求
void use(unique_ptr< http_filter > middleware)
添加中间件
void get_post(const string &path, http_handler_t handler)
同时注册GET和POST
http_server_response http_response
HTTP响应类型别名
http_server_request http_request
HTTP请求类型别名
constexpr Iterator2 move(Iterator1 first, Iterator1 last, Iterator2 result) noexcept(noexcept(inner::__move_aux(first, last, result)))
移动范围元素