fastdo  0.6.8
webx_HttpApp.hpp
浏览该文件的文档.
1 #pragma once
2 
3 namespace eienwebx
4 {
7 {
11 };
12 
13 class HttpRequestCtx;
14 
19 {
20 public:
22 
24  static void InitPrivateData();
25 
27  using CrossRouteHandlerFunction = std::function< bool ( winux::SharedPointer<HttpRequestCtx> requestCtxPtr, eienwebx::Response & rsp, winux::StringArray & urlPathPartArr, size_t i ) >;
29  using RouteHandlerFunction = std::function< void ( winux::SharedPointer<HttpRequestCtx> requestCtxPtr, eienwebx::Response & rsp ) >;
30 
32  HttpApp();
33 
35  HttpApp( winux::ConfigureSettings const & settings, AppServerExternalData * externalData );
36 
48  HttpApp(
49  winux::ConfigureSettings const & settings,
50  AppServerExternalData * externalData,
51  eiennet::ip::EndPoint const & ep,
52  int threadCount = 4,
53  int backlog = 0,
54  double serverWait = 0.002,
55  double verboseInterval = 0.01,
56  bool verbose = true,
57  int cacheLifeTime = 86400
58  );
59 
61  bool init( winux::ConfigureSettings const & settings, AppServerExternalData * externalData );
62 
74  bool init(
75  winux::ConfigureSettings const & settings,
76  AppServerExternalData * externalData,
77  eiennet::ip::EndPoint const & ep,
78  int threadCount = 4,
79  int backlog = 0,
80  double serverWait = 0.002,
81  double verboseInterval = 0.01,
82  bool verbose = true,
83  int cacheLifeTime = 86400
84  );
85 
91  void crossRoute( winux::String const & method, winux::String const & path, CrossRouteHandlerFunction handler );
92 
98  void route( winux::String const & method, winux::String const & path, RouteHandlerFunction handler );
99 
101  virtual int run( void * runParam ) override;
102 
105 
106 protected:
107  virtual void onClientDataArrived( winux::SharedPointer<eiennet::ClientCtx> clientCtxPtr, winux::Buffer data ) override;
108 
109  virtual eiennet::ClientCtx * onCreateClient( winux::uint64 clientId, winux::String const & clientEpStr, winux::SharedPointer<eiennet::ip::tcp::Socket> clientSockPtr ) override;
110 
111  void _onClientRequestInternal( winux::SharedPointer<HttpRequestCtx> httpClientCtxPtr, http::Header & header, winux::AnsiString & body );
112 
115  // 路由处理器
117  std::vector< std::unordered_map< winux::String, std::unordered_map< winux::String, CrossRouteHandlerFunction > > > _crossRouter;
119  std::unordered_map< winux::String, std::unordered_map< winux::String, RouteHandlerFunction > > _router;
120 
121  // 处理一个WebMain逻辑
123  void,
124  WebMain,
126  );
127 
128  friend class HttpRequestCtx;
129 };
130 
131 } // namespace eienwebx
XString< char > AnsiString
Definition: utilities.hpp:212
代表HTTP头部
Definition: http_misc.hpp:10
基础客户场景类
std::vector< std::unordered_map< winux::String, std::unordered_map< winux::String, CrossRouteHandlerFunction > > > _crossRouter
过径路由器 [ { pathpart: { GET: handleGet, POST: handlePost, ... }, ... }, ... ]
HTTP客户请求场景
#define EIENWEBX_DLL
XString< tchar > String
Definition: utilities.hpp:216
Web功能的相关封装
更强大的配置文件类
Definition: archives.hpp:72
eiennet::StaticFileMemoryCache _staticFileCache
静态文件缓存
HttpServer配置参数
静态文件内存缓存(带互斥锁)
App类,内部有Do文件载入/执行功能
Definition: webx_App.hpp:13
缓冲区,表示内存中一块二进制数据(利用malloc/realloc进行内存分配)
Definition: utilities.hpp:528
HttpApp私有数据
Definition: webx_HttpApp.hpp:6
#define DEFINE_CUSTOM_EVENT_RETURN_EX(ret, evtname, paramtypes)
Definition: utilities.hpp:152
代表一个客户响应
基础服务器类
static HttpAppPrivateData PrivateData
std::function< void(winux::SharedPointer< HttpRequestCtx > requestCtxPtr, eienwebx::Response &rsp) > RouteHandlerFunction
终点路由处理函数类型
std::function< bool(winux::SharedPointer< HttpRequestCtx > requestCtxPtr, eienwebx::Response &rsp, winux::StringArray &urlPathPartArr, size_t i) > CrossRouteHandlerFunction
过径路由处理函数类型
unsigned __int64 uint64
Definition: utilities.hpp:185
std::unordered_map< winux::String, std::unordered_map< winux::String, RouteHandlerFunction > > _router
普通路由器 { path: { GET: handleGet, POST: handlePost, ... }, ... }
XStringArray< tchar > StringArray
Definition: utilities.hpp:227
App服务器外部定义的公开数据
Definition: appserv.hpp:7
eiennet::HttpServerConfig httpConfig
HTTP服务器配置对象