2023-12-10 23:23:15 +00:00
|
|
|
// 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-13 20:33:11 +00:00
|
|
|
#include "handler/handler.h"
|
2023-11-23 19:57:32 +00:00
|
|
|
|
2023-12-07 20:32:43 +00:00
|
|
|
class Server;
|
|
|
|
|
2023-11-23 19:57:32 +00:00
|
|
|
class Router {
|
2023-12-13 20:33:11 +00:00
|
|
|
using Handler = std::unique_ptr<Handler::Handler>;
|
2023-11-23 19:57:32 +00:00
|
|
|
public:
|
|
|
|
Router();
|
|
|
|
|
2023-12-13 20:33:11 +00:00
|
|
|
void addRoute(Handler handler);
|
|
|
|
void route(const std::string& path, std::unique_ptr<Request> request);
|
2023-11-23 19:57:32 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
void handleNotFound(const std::string& path, std::unique_ptr<Request> request);
|
2023-12-13 20:33:11 +00:00
|
|
|
void handleInternalError(const std::string& path, const std::exception& exception, std::unique_ptr<Request> request);
|
|
|
|
void handleMethodNotAllowed(const std::string& path, std::unique_ptr<Request> request);
|
2023-11-23 19:57:32 +00:00
|
|
|
|
|
|
|
private:
|
2023-12-13 20:33:11 +00:00
|
|
|
std::map<std::string, Handler> get;
|
|
|
|
std::map<std::string, Handler> post;
|
2023-11-23 19:57:32 +00:00
|
|
|
|
|
|
|
};
|