1
0
forked from blue/pica
pica/server/router.h
2023-12-28 17:26:08 -03:00

35 lines
808 B
C++

// SPDX-FileCopyrightText: 2023 Yury Gubich <blue@macaw.me>
// SPDX-License-Identifier: GPL-3.0-or-later
#pragma once
#include <map>
#include <functional>
#include <string>
#include <memory>
#include "request/request.h"
#include "response/response.h"
#include "handler/handler.h"
class Server;
class Router {
using Handler = std::unique_ptr<Handler::Handler>;
public:
Router();
void addRoute(Handler handler);
void route(std::unique_ptr<Request> request);
private:
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);
private:
std::map<std::string, Handler> get;
std::map<std::string, Handler> post;
};