VWeb/Source/MiddleWare.cpp

39 lines
1.1 KiB
C++
Raw Normal View History

2022-08-23 14:13:21 +02:00
#include <VWeb.h>
namespace VWeb {
2022-08-23 16:40:57 +02:00
std::optional<Ref<Response>>
MiddleWareHandler::HandlePre(Ref<Request> &request) {
2022-08-23 14:13:21 +02:00
for (auto &[key, middleWare] : m_MiddleWares) {
2022-08-23 16:40:57 +02:00
auto data = middleWare->PreHandle(*request);
if (data.has_value())
return data;
2022-08-23 14:13:21 +02:00
}
2022-08-23 16:40:57 +02:00
return {};
2022-08-23 14:13:21 +02:00
}
void MiddleWareHandler::HandlePost(Ref<Request> &request,
Ref<Response> &response) {
for (auto &[key, middleWare] : m_MiddleWares) {
2022-08-23 16:40:57 +02:00
if (!middleWare->PostHandle(*request, *response)) {
break;
}
2022-08-23 14:13:21 +02:00
}
}
void MiddleWareHandler::Shutdown(Ref<Request> &request,
Ref<Response> &response) {
for (auto &[key, middleWare] : m_MiddleWares) {
middleWare->Shutdown(*request, *response);
}
}
Ref<MiddleWare> MiddleWareHandler::GetById(const char *id) {
return m_MiddleWares[id];
}
Ref<MiddleWare> MiddleWareHandler::SetById(const char *id,
const Ref<MiddleWare> &middleWare) {
m_MiddleWares[id] = middleWare;
return middleWare;
}
void MiddleWareHandler::RemoveById(const char *id) {
if (m_MiddleWares.contains(id))
m_MiddleWares.erase(id);
}
} // namespace VWeb