NAWA 0.9
Web Application Framework for C++
RequestHandler.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019-2022 Tobias Flaig.
3 *
4 * This file is part of nawa.
5 *
6 * nawa is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU Lesser General Public License,
8 * version 3, as published by the Free Software Foundation.
9 *
10 * nawa is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with nawa. If not, see <https://www.gnu.org/licenses/>.
17 */
18
24#ifndef NAWA_REQUESTHANDLER_H
25#define NAWA_REQUESTHANDLER_H
26
27#include <memory>
29#include <nawa/config/Config.h>
33#include <optional>
34
35namespace nawa {
38
39 protected:
41
42 public:
47 virtual ~RequestHandler();
48
59 static std::unique_ptr<RequestHandler>
60 newRequestHandler(std::shared_ptr<HandleRequestFunctionWrapper> const& handleRequestFunction, Config config,
61 int concurrency);
62
73 static std::unique_ptr<RequestHandler>
74 newRequestHandler(HandleRequestFunction handleRequestFunction, Config config, int concurrency);
75
81 void setAppRequestHandler(std::shared_ptr<HandleRequestFunctionWrapper> handleRequestFunction) noexcept;
82
87 void setAccessFilters(AccessFilterList accessFilters) noexcept;
88
93 [[nodiscard]] std::shared_ptr<Config const> getConfig() const noexcept;
94
100 void setConfig(Config config) noexcept;
101
108 void reconfigure(std::optional<std::shared_ptr<HandleRequestFunctionWrapper>> handleRequestFunction,
109 std::optional<AccessFilterList> accessFilters, std::optional<Config> config) noexcept;
110
117 void reconfigure(HandleRequestFunction handleRequestFunction, std::optional<AccessFilterList> accessFilters,
118 std::optional<Config> config) noexcept;
119
129 virtual void start() = 0;
130
135 virtual void stop() noexcept = 0;
136
143 virtual void terminate() noexcept = 0;
144
150 virtual void restart() noexcept {}
151
157 virtual void join() noexcept = 0;
158
164 void handleRequest(Connection& connection);
165 };
166}// namespace nawa
167
168#endif//NAWA_REQUESTHANDLER_H
Options to check the path and invoke certain actions before forwarding the request to the app.
Reader for config files and accessor to config values.
Function wrapper for handleRequest functions of nawa apps.
virtual void stop() noexcept=0
virtual void start()=0
virtual void restart() noexcept
static std::unique_ptr< RequestHandler > newRequestHandler(std::shared_ptr< HandleRequestFunctionWrapper > const &handleRequestFunction, Config config, int concurrency)
std::shared_ptr< Config const > getConfig() const noexcept
void handleRequest(Connection &connection)
void setConfig(Config config) noexcept
virtual void join() noexcept=0
void setAccessFilters(AccessFilterList accessFilters) noexcept
void reconfigure(std::optional< std::shared_ptr< HandleRequestFunctionWrapper > > handleRequestFunction, std::optional< AccessFilterList > accessFilters, std::optional< Config > config) noexcept
virtual void terminate() noexcept=0
void setAppRequestHandler(std::shared_ptr< HandleRequestFunctionWrapper > handleRequestFunction) noexcept
Forward declarations.
Macros for frequently used patterns.
#define NAWA_DEFAULT_CONSTRUCTOR_DEF(Class)
Definition: macros.h:39
#define NAWA_PRIVATE_DATA()
Definition: macros.h:30
Definition: AppInit.h:31
std::function< int(nawa::Connection &)> HandleRequestFunction