fastdo  0.6.16
http_HttpServer.hpp
浏览该文件的文档.
1 #pragma once
2 
3 namespace http
4 {
7 {
8 public:
19 
25 
27  HttpServer();
28 
32  HttpServer( winux::ConfigureSettings const & settings );
33 
44  HttpServer(
45  winux::ConfigureSettings const & settings,
46  eiennet::ip::EndPoint const & ep,
47  int threadCount = 4,
48  int backlog = 0,
49  double serverWait = 0.002,
50  double verboseInterval = 0.01,
52  int cacheLifeTime = 86400
53  );
54 
59  bool init( winux::ConfigureSettings const & settings );
60 
72  bool init(
73  winux::ConfigureSettings const & settings,
74  eiennet::ip::EndPoint const & ep,
75  int threadCount = 4,
76  int backlog = 0,
77  double serverWait = 0.002,
78  double verboseInterval = 0.01,
80  int cacheLifeTime = 86400
81  );
82 
88  void crossRoute( winux::String const & method, winux::String const & path, CrossRouteHandlerFunction handler );
89 
95  void route( winux::String const & method, winux::String const & path, RouteHandlerFunction handler );
96 
98  virtual int run( void * runParam ) override;
99 
102 
103 protected:
104  // 当创建客户连接
105  virtual eiennet::ClientCtx * onCreateClient( winux::uint64 clientId, winux::String const & clientEpStr, winux::SharedPointer<eiennet::ip::tcp::Socket> clientSockPtr ) override;
106  // 当客户数据到达
107  virtual void onClientDataArrived( winux::SharedPointer<eiennet::ClientCtx> clientCtxPtr, winux::Buffer & data ) override;
109  void _onHttpRequestInternal( winux::SharedPointer<HttpRequestCtx> requestCtxPtr );
111  virtual bool _beginHttpRequest( winux::SharedPointer<http::HttpRequestCtx> requestCtxPtr, http::UrlPathPartData * urlData );
113  virtual void _endHttpRequest( winux::SharedPointer<http::HttpRequestCtx> requestCtxPtr );
115  virtual bool _beginRouting( winux::SharedPointer<http::HttpRequestCtx> requestCtxPtr, http::UrlPathPartData const & urlData, http::Response & rsp ) { return true; }
117  virtual void _endRouting( winux::SharedPointer<http::HttpRequestCtx> requestCtxPtr, http::UrlPathPartData const & urlData, http::Response & rsp ) { }
118 
120  virtual void _whatNextTask( winux::SharedPointer<HttpRequestCtx> requestCtxPtr );
121 
123  virtual void _doTask( winux::SharedPointer<http::HttpRequestCtx> requestCtxPtr );
124 
126  void _doRecvRequestHeaderTask( winux::SharedPointer<HttpRequestCtx> requestCtxPtr );
127 
129  void _doRecvRequestBodyTask( winux::SharedPointer<HttpRequestCtx> requestCtxPtr );
130 
131  // 创建响应
137  Response *,
138  CreateResponse,
139  ( Request & req, winux::SimplePointer<RspOutputMgr> outputMgr )
140  );
141 
142  friend class HttpRequestCtx;
143 };
144 
145 
146 } // 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路由器
XString< tchar > String
Definition: utilities.hpp:261
更强大的配置文件类
Definition: archives.hpp:71
HTTP协议的相关简单类封装
Definition: http_base.hpp:32
std::function< void(winux::SharedPointer< _ReqClass > requestPtr, _RspClass &rsp) > RouteHandlerFunctionT
普通路由处理函数类型
在控制台输出
RouteHandlerFunctionT< HttpRequestCtx, Response > RouteHandlerFunction
普通路由处理函数类型
HTTP服务器
HTTP请求
Definition: http_Request.hpp:8
引用计数共享指针
Definition: smartptr.hpp:456
缓冲区,表示内存中一块二进制数据(利用malloc/realloc进行内存分配)
Definition: utilities.hpp:906
#define DEFINE_CUSTOM_EVENT_RETURN_EX(ret, evtname, paramtypes)
Definition: utilities.hpp:197
基础服务器类
VerboseOutputType
冗余信息输出类型
virtual bool _beginRouting(winux::SharedPointer< http::HttpRequestCtx > requestCtxPtr, http::UrlPathPartData const &urlData, http::Response &rsp)
开始路由。返回false表示不路由
virtual void _endRouting(winux::SharedPointer< http::HttpRequestCtx > requestCtxPtr, http::UrlPathPartData const &urlData, http::Response &rsp)
结束路由
HTTP响应
简单指针
Definition: smartptr.hpp:302
CrossRouteHandlerFunctionT< HttpRequestCtx, Response > CrossRouteHandlerFunction
过径路由处理函数类型
HTTP客户请求场景
unsigned __int64 uint64
Definition: utilities.hpp:230
HttpServerConfig httpConfig
HTTP服务器配置对象