2
3
4
5
28 m_Server.AddConnectionCallback(std::bind(&HttpServer::OnConnection,
this, std::placeholders::_1));
29 m_Server.AddMessageCallback(std::bind(&HttpServer::OnMessage,
this, std::placeholders::_1, std::placeholders::_2));
36 m_Server.Start(threadSize);
43 if (connection->Connected())
45 SPICES_CORE_INFO(
"New Http Connection")
47 m_ConnectionList.push_back(connection);
49 Node node = --m_ConnectionList.end();
50 m_NameNodeMap[connection->GetName()] = node;
54 SPICES_CORE_INFO(
"Http Connection Closed")
56 assert(m_NameNodeMap.count(connection->GetName()));
57 const Node& node = m_NameNodeMap[connection->GetName()];
58 m_NameNodeMap.erase(connection->GetName());
59 m_ConnectionList.erase(node);
69 assert(m_NameNodeMap.count(connection->GetName()));
70 Node node = m_NameNodeMap[connection->GetName()];
72 m_ConnectionList.splice(m_ConnectionList.end(), m_ConnectionList, node);
73 assert(node == --m_ConnectionList.end());
75 if (!context->ParseRequest(buf))
77 SPICES_CORE_INFO(
"HttpContext ParseRequest Failed")
79 connection->Send(
"HTTP/1.1 400 Bad Request\r\n\r\n");
80 connection->ShutDown();
83 if (context->GotAll())
85 SPICES_CORE_INFO(
"HttpContext ParseRequest Succeed")
87 OnRequest(connection, context->GetRequest());
96 std::string connectionHeader = request
.GetHeader(
"Connection");
101 m_HttpCallback(request, &response);
105 connection->Send(buf.RetrieveAllAsString());
109 connection->ShutDown();
#define SPICES_PROFILE_ZONE
Wrapper of readwrite buffer.
const Version GetVersion() const
Get Http Version.
std::string GetHeader(const std::string &name) const
Get a Header from this HttpRequest.
HttpResponse(bool close)
Constructor Function.
void AppendToBuffer(Buffer *output)
Append this response to Buffer.
bool CloseConnection() const
Get CloseConnection.
void OnRequest(const TcpConnectionPtr &connection, const HttpRequest &request)
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.
void OnMessage(const TcpConnectionPtr &connection, Buffer *buf)
This class is Wrapper of current socket address.