SpiecsEngine
 
Loading...
Searching...
No Matches
HttpServer.h
Go to the documentation of this file.
1/**
2* @file HttpServer.h.
3* @brief The HttpServer Class Definitions.
4* @author Spices & Muduo.
5*/
6
7#pragma once
8#include "Core/Core.h"
9#include "Network/Net/TcpServer.h"
10
11namespace Spices {
12
13namespace Net {
14
15 class HttpRequest;
16 class HttpResponse;
17
19 {
20 public:
21
22 using HttpCallback = std::function<void(const HttpRequest&, HttpResponse*)>;
23 using WeakTcpConnectionPtr = std::weak_ptr<TcpConnection>;
25
28
29 public:
30
31 /**
32 * @brief Constructor Function.
33 * @param[in] listenAddress Server listen address.
34 * @param[in] idleSeconds .
35 * @param[in] option Is reuse port.
36 */
38 const InetAddress& listenAddress ,
39 int idleSeconds ,
41 );
42
43 /**
44 * @brief Destructor Function.
45 */
46 virtual ~HttpServer() = default;
47
48 /**
49 * @brief Copy Constructor Function.
50 * @note This Class not allowed copy behaves.
51 */
52 HttpServer(const HttpServer&) = delete;
53
54 /**
55 * @brief Copy Assignment Operation.
56 * @note This Class not allowed copy behaves.
57 */
58 HttpServer& operator=(const HttpServer&) = delete;
59
60 /**
61 * @brief Start ThreadPool and call listen on acceptor.
62 * @param[in] threadSize ThreadPool size.
63 */
64 void Start(int threadSize) const;
65
66 private:
67
68 void OnConnection(const TcpConnectionPtr& connection);
69 void OnMessage(const TcpConnectionPtr& connection, Buffer* buf);
70 void OnRequest(const TcpConnectionPtr& connection, const HttpRequest& request);
71
72 private:
73
75 HttpCallback m_HttpCallback;
77
80 };
81
82}
83
84}
#define SPICES_PROFILE_ZONE
Wrapper of readwrite buffer.
Definition Buffer.h:19
const Version GetVersion() const
Get Http Version.
Definition HttpRequest.h:89
std::string GetHeader(const std::string &name) const
Get a Header from this HttpRequest.
Http Request body.
Definition HttpRequest.h:18
HttpResponse(bool close)
Constructor Function.
void AppendToBuffer(Buffer *output)
Append this response to Buffer.
bool CloseConnection() const
Get CloseConnection.
HttpServer & operator=(const HttpServer &)=delete
Copy Assignment Operation.
HttpServer(const HttpServer &)=delete
Copy Constructor Function.
void OnRequest(const TcpConnectionPtr &connection, const HttpRequest &request)
HttpCallback m_HttpCallback
Definition HttpServer.h:75
virtual ~HttpServer()=default
Destructor Function.
void OnConnection(const TcpConnectionPtr &connection)
HttpServer(const InetAddress &listenAddress, int idleSeconds, TcpServer::Option option=TcpServer::Option::NoReusePort)
Constructor Function.
void Start(int threadSize) const
Start ThreadPool and call listen on acceptor.
WeakConnectionList m_ConnectionList
Definition HttpServer.h:78
void OnMessage(const TcpConnectionPtr &connection, Buffer *buf)
This class is Wrapper of current socket address.
Definition InetAddress.h:22
Combine of Socket Connection data.
Sample of a TcpServer.
Definition TcpServer.h:29