#pragma once #include "MiddleWareHandler.h" #include "Queue.h" #include "Request.h" #include "Router.h" #include "SocketManager.h" #include "ThreadPool.h" #include namespace VWeb { class Server; typedef std::function ParseFunction; class RequestHandler { public: explicit RequestHandler(const Ref &manager); void InitThreads(int count); void AddRequest(Ref &request); void Stop(); void SetRouter(Ref &router); void AddSendResponse(SendData); void CloseRequest(int id) const; Ref &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 m_ParseFunctions; Ref m_Router{nullptr}; Ref m_SocketManager{nullptr}; Server *m_Server{nullptr}; SafeQueue> m_Requests{}; ThreadPool m_Pool{"RequestHandler"}; Ref m_MiddleWare{nullptr}; friend Server; }; } // namespace VWeb