Fix: Router Functions are the same weight as classes
also added some basic tests for it.
This commit is contained in:
parent
516e33d165
commit
f001b24749
7 changed files with 138 additions and 13 deletions
|
|
@ -123,6 +123,10 @@ struct RequestJob : public WorkerJob {
|
|||
MRequestHandler->AddSendResponse(
|
||||
{0, (ssize_t)content.size(), MRequest->ID, content});
|
||||
MMiddleWareHandler->Shutdown(MRequest, response);
|
||||
} catch (const std::bad_alloc &e) {
|
||||
// We are out of memory... try to clean up some request...
|
||||
SocketUtils::Close(MRequest->ID);
|
||||
MRequestHandler->CloseRequest(MRequest->ID);
|
||||
} catch (const std::exception &e) {
|
||||
fprintf(stderr,
|
||||
"[VWEB] >> Failed to handle Requests... Error thrown\n%s\n",
|
||||
|
|
@ -157,8 +161,11 @@ void RequestHandler::AddSendResponse(SendData sendData) {
|
|||
auto id = sendData.SocketID;
|
||||
m_Server->m_OutRequest.Add(id, sendData);
|
||||
if (!m_SocketManager->SetSendListen(id)) {
|
||||
SocketUtils::Close(id);
|
||||
m_Server->m_OutRequest.Remove(id);
|
||||
CloseRequest(id);
|
||||
}
|
||||
}
|
||||
void RequestHandler::CloseRequest(const int id) const {
|
||||
SocketUtils::Close(id);
|
||||
m_Server->m_OutRequest.Remove(id);
|
||||
}
|
||||
} // namespace VWeb
|
||||
|
|
|
|||
|
|
@ -156,28 +156,23 @@ struct InlineRoute : Route {
|
|||
};
|
||||
|
||||
void Router::Get(const std::string &path, const RouteFunction &func) {
|
||||
m_Tree.Add(s_HttpMethodToString[HttpMethod::GET] + path,
|
||||
(uint32_t)HttpMethod::GET,
|
||||
m_Tree.Add(path, static_cast<uint32_t>(HttpMethod::GET),
|
||||
[func] { return std::make_shared<InlineRoute>(func); });
|
||||
}
|
||||
void Router::Post(const std::string &path, const RouteFunction &func) {
|
||||
m_Tree.Add(s_HttpMethodToString[HttpMethod::POST] + path,
|
||||
(uint32_t)HttpMethod::POST,
|
||||
m_Tree.Add(path, static_cast<uint32_t>(HttpMethod::POST),
|
||||
[func] { return std::make_shared<InlineRoute>(func); });
|
||||
}
|
||||
void Router::Put(const std::string &path, const RouteFunction &func) {
|
||||
m_Tree.Add(s_HttpMethodToString[HttpMethod::PUT] + path,
|
||||
(uint32_t)HttpMethod::PUT,
|
||||
m_Tree.Add(path, static_cast<uint32_t>(HttpMethod::PUT),
|
||||
[func] { return std::make_shared<InlineRoute>(func); });
|
||||
}
|
||||
void Router::Patch(const std::string &path, const RouteFunction &func) {
|
||||
m_Tree.Add(s_HttpMethodToString[HttpMethod::PATCH] + path,
|
||||
(uint32_t)HttpMethod::PATCH,
|
||||
m_Tree.Add(path, static_cast<uint32_t>(HttpMethod::PATCH),
|
||||
[func] { return std::make_shared<InlineRoute>(func); });
|
||||
}
|
||||
void Router::Delete(const std::string &path, const RouteFunction &func) {
|
||||
m_Tree.Add(s_HttpMethodToString[HttpMethod::DELETE] + path,
|
||||
(uint32_t)HttpMethod::DELETE,
|
||||
m_Tree.Add(path, static_cast<uint32_t>(HttpMethod::DELETE),
|
||||
[func] { return std::make_shared<InlineRoute>(func); });
|
||||
}
|
||||
} // namespace VWeb
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue