#pragma once #include #include #include #include #include #include #include #include "WebCommon.h" namespace WebServer { class WebServer { public: WebServer(std::uint16_t port); typedef std::function handler_t; bool RegisterPathHandler(const std::string& method, const std::string& path, handler_t&& handler); void RegisterDefaultHandler(handler_t&& handler); bool Run(volatile bool* run); private: // Dispatch requests by mapping from (method, path) to handler. // Dispatch key is (method, path) in that order. typedef std::tuple dispatch_key_t; static inline dispatch_key_t GetDispatchKey(const std::string& method, const std::string& path) { return dispatch_key_t(method, path); } typedef std::map dispatch_map_t; dispatch_map_t dispatch_map_; handler_t default_handler_; const uint16_t port_; std::vector> connections_; }; }