fastdo  0.6.16
http_UrlRouter.hpp
浏览该文件的文档.
1 #pragma once
2 
3 namespace http
4 {
14 template < class _ReqClass, class _RspClass >
15 using CrossRouteHandlerFunctionT = std::function< bool ( winux::SharedPointer<_ReqClass> requestPtr, _RspClass & rsp, winux::StringArray const & urlPathPartArr, size_t i ) >;
16 
21 template < class _ReqClass, class _RspClass >
22 using RouteHandlerFunctionT = std::function< void ( winux::SharedPointer<_ReqClass> requestPtr, _RspClass & rsp ) >;
23 
26 {
27 public:
30 
32  UrlRouter( http::HttpServerConfig * httpConfig = nullptr );
33 
35  virtual ~UrlRouter();
36 
38  bool init( http::HttpServerConfig * httpConfig );
39 
45  void crossRoute( winux::String const & method, winux::String const & path, CrossRouteHandlerFunction handler );
46 
52  void route( winux::String const & method, winux::String const & path, RouteHandlerFunction handler );
53 
54 protected:
56  virtual void routing( winux::SharedPointer<http::Request> requestPtr, http::UrlPathPartData const & urlData, http::Response & rsp );
57 
60  // 路由处理器
66  std::vector< std::unordered_map< winux::String, std::unordered_map< winux::String, CrossRouteHandlerFunction > > > _crossRouter;
72  std::unordered_map< winux::String, std::unordered_map< winux::String, RouteHandlerFunction > > _router;
73 
74  // 处理一个WebMain逻辑
80  void,
81  WebMain,
83  );
84 
85  // 文件扩展名处理,返回true表示成功处理,返回false表示没有处理
96  bool,
97  ExtensionHandling,
98  ( winux::String const & extName, winux::String const & fullPath, winux::SharedPointer<http::Request> requestPtr, http::Response & rsp )
99  );
100 
101 private:
102  http::HttpServerConfig * _httpConfig;
103 
104 };
105 
106 
107 } // namespace http
std::function< bool(winux::SharedPointer< _ReqClass > requestPtr, _RspClass &rsp, winux::StringArray const &urlPathPartArr, size_t i) > CrossRouteHandlerFunctionT
过径路由处理函数类型
HttpServer配置参数
#define HTTPWRAPPER_DLL
Definition: http_base.hpp:24
处理URL路径部分时的一些中间变量
Definition: http_misc.hpp:12
URL路由器
std::unordered_map< winux::String, std::unordered_map< winux::String, RouteHandlerFunction > > _router
普通路由器
XString< tchar > String
Definition: utilities.hpp:261
HTTP协议的相关简单类封装
Definition: http_base.hpp:32
std::function< void(winux::SharedPointer< _ReqClass > requestPtr, _RspClass &rsp) > RouteHandlerFunctionT
普通路由处理函数类型
RouteHandlerFunctionT< http::Request, http::Response > RouteHandlerFunction
http::StaticFileMemoryCache _staticFileCache
静态文件缓存
CrossRouteHandlerFunctionT< http::Request, http::Response > CrossRouteHandlerFunction
引用计数共享指针
Definition: smartptr.hpp:456
#define DEFINE_CUSTOM_EVENT_RETURN_EX(ret, evtname, paramtypes)
Definition: utilities.hpp:197
静态文件内存缓存(带互斥锁)
HTTP响应
std::vector< std::unordered_map< winux::String, std::unordered_map< winux::String, CrossRouteHandlerFunction > > > _crossRouter
过径路由器
XStringArray< tchar > StringArray
Definition: utilities.hpp:272