pica/server/router.h

30 lines
669 B
C
Raw Normal View History

2023-11-23 19:57:32 +00:00
#pragma once
#include <map>
#include <functional>
#include <string>
#include <memory>
#include "request/request.h"
#include "response/response.h"
2023-12-07 20:32:43 +00:00
class Server;
2023-11-23 19:57:32 +00:00
class Router {
public:
2023-12-07 20:32:43 +00:00
using Handler = std::function<bool(Request*, Server*)>;
2023-11-23 19:57:32 +00:00
Router();
void addRoute(const std::string& path, const Handler& handler);
2023-12-07 20:32:43 +00:00
void route(const std::string& path, std::unique_ptr<Request> request, Server* server);
2023-11-23 19:57:32 +00:00
private:
void handleNotFound(const std::string& path, std::unique_ptr<Request> request);
void handleInternalError(const std::exception& exception, std::unique_ptr<Request> request);
private:
std::map<std::string, Handler> table;
};