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

35 lines
804 B
C
Raw Normal View History

2023-12-30 22:42:11 +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);
2023-12-28 20:26:08 +00:00
void route(std::unique_ptr<Request> request);
2023-11-23 19:57:32 +00:00
private:
2023-12-28 20:26:08 +00:00
void handleNotFound(std::unique_ptr<Request> request);
void handleInternalError(const std::exception& exception, std::unique_ptr<Request> request);
void handleMethodNotAllowed(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
};