VWeb/Includes/RequestHandler.h
Maurice Grönwoldt 5bb68a7d02 Split VWeb into smaller headers
We have no make install support... so we don't need to have everything as a single-header and lib file.
2023-09-16 16:29:03 +02:00

42 lines
1.1 KiB
C++

#pragma once
#include "MiddleWareHandler.h"
#include "Queue.h"
#include "Request.h"
#include "Router.h"
#include "SocketManager.h"
#include "ThreadPool.h"
#include <functional>
namespace VWeb {
class Server;
typedef std::function<const void(Request &, const std::string &body)>
ParseFunction;
class RequestHandler {
public:
explicit RequestHandler(const Ref<SocketManager> &manager);
void InitThreads(int count);
void AddRequest(Ref<Request> &request);
void Stop();
void SetRouter(Ref<Router> &router);
void AddSendResponse(SendData);
Ref<MiddleWareHandler> &Middleware() { return m_MiddleWare; }
bool HasBodyParser(const std::string &key) {
return m_ParseFunctions.contains(key);
}
ParseFunction &GetBodyParser(const std::string &key) {
return m_ParseFunctions.at(key);
}
protected:
std::unordered_map<std::string, ParseFunction> m_ParseFunctions;
Ref<Router> m_Router{nullptr};
Ref<SocketManager> m_SocketManager{nullptr};
Server *m_Server{nullptr};
SafeQueue<Ref<Request>> m_Requests{};
ThreadPool m_Pool{"RequestHandler"};
Ref<MiddleWareHandler> m_MiddleWare{nullptr};
friend Server;
};
} // namespace VWeb