1
0
forked from blue/pica
pica/server/router.h

30 lines
669 B
C++

#pragma once
#include <map>
#include <functional>
#include <string>
#include <memory>
#include "request/request.h"
#include "response/response.h"
class Server;
class Router {
public:
using Handler = std::function<bool(Request*, Server*)>;
Router();
void addRoute(const std::string& path, const Handler& handler);
void route(const std::string& path, std::unique_ptr<Request> request, Server* server);
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;
};