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

33 lines
777 B
C
Raw Normal View History

// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
// SPDX-License-Identifier: GPL-3.0-or-later
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;
};