NAWA 0.8
Web Application Framework for C++
RequestHandler.h
Go to the documentation of this file.
1
6/*
7 * Copyright (C) 2019-2021 Tobias Flaig.
8 *
9 * This file is part of nawa.
10 *
11 * nawa is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License,
13 * version 3, as published by the Free Software Foundation.
14 *
15 * nawa is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public License
21 * along with nawa. If not, see <https://www.gnu.org/licenses/>.
22 */
23
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:
46 virtual ~RequestHandler();
47
58 static std::unique_ptr<RequestHandler>
59 newRequestHandler(std::shared_ptr<HandleRequestFunctionWrapper> const& handleRequestFunction, Config config,
60 int concurrency);
61
72 static std::unique_ptr<RequestHandler>
73 newRequestHandler(HandleRequestFunction handleRequestFunction, Config config, int concurrency);
74
80 void setAppRequestHandler(std::shared_ptr<HandleRequestFunctionWrapper> handleRequestFunction) noexcept;
81
86 void setAccessFilters(AccessFilterList accessFilters) noexcept;
87
92 [[nodiscard]] std::shared_ptr<Config const> getConfig() const noexcept;
93
99 void setConfig(Config config) noexcept;
100
107 void reconfigure(std::optional<std::shared_ptr<HandleRequestFunctionWrapper>> handleRequestFunction,
108 std::optional<AccessFilterList> accessFilters, std::optional<Config> config) noexcept;
109
116 void reconfigure(HandleRequestFunction handleRequestFunction, std::optional<AccessFilterList> accessFilters,
117 std::optional<Config> config) noexcept;
118
128 virtual void start() = 0;
129
134 virtual void stop() noexcept = 0;
135
142 virtual void terminate() noexcept = 0;
143
149 virtual void restart() noexcept {}
150
156 virtual void join() noexcept = 0;
157
163 void handleRequest(Connection& connection);
164 };
165}// namespace nawa
166
167#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 ~RequestHandler()
virtual void stop() noexcept=0
std::shared_ptr< Config const > getConfig() const noexcept
virtual void start()=0
virtual void restart() noexcept
void handleRequest(Connection &connection)
void setConfig(Config config) noexcept
virtual void join() noexcept=0
void setAccessFilters(AccessFilterList accessFilters) noexcept
static std::unique_ptr< RequestHandler > newRequestHandler(std::shared_ptr< HandleRequestFunctionWrapper > const &handleRequestFunction, Config config, int concurrency)
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