31#include <shared_mutex>
36struct RequestHandler::Data {
37 shared_mutex configurationMutex;
38 shared_ptr<HandleRequestFunctionWrapper> handleRequestFunction;
39 shared_ptr<AccessFilterList> accessFilters;
40 shared_ptr<Config> config;
46 unique_lock l(data->configurationMutex);
47 data->handleRequestFunction = std::move(handleRequestFunction);
51 unique_lock l(data->configurationMutex);
52 data->accessFilters = make_shared<AccessFilterList>(std::move(accessFilters));
55void RequestHandler::setConfig(
Config config)
noexcept {
56 unique_lock l(data->configurationMutex);
57 data->config = make_shared<Config>(std::move(config));
60std::shared_ptr<Config const> RequestHandler::getConfig() const noexcept {
65 std::optional<AccessFilterList> accessFilters,
66 std::optional<Config> config)
noexcept {
67 unique_lock l(data->configurationMutex);
68 if (handleRequestFunction) {
69 data->handleRequestFunction = *handleRequestFunction;
72 data->accessFilters = make_shared<AccessFilterList>(std::move(*accessFilters));
75 data->config = make_shared<Config>(std::move(*config));
80 std::optional<Config> config)
noexcept {
81 reconfigure(make_shared<HandleRequestFunctionWrapper>(std::move(handleRequestFunction)), std::move(accessFilters),
86 shared_ptr<HandleRequestFunctionWrapper> handleRequestFunction;
87 shared_ptr<AccessFilterList> accessFilters;
88 shared_ptr<Config> config;
90 shared_lock l(data->configurationMutex);
91 handleRequestFunction = data->handleRequestFunction;
92 accessFilters = data->accessFilters;
95 if (!accessFilters || !connection.
applyFilters(*accessFilters)) {
96 (*handleRequestFunction)(connection);
100std::unique_ptr<RequestHandler>
102 Config config,
int concurrency) {
103 if (config[{
"system",
"request_handler"}] ==
"http") {
104 return make_unique<HttpRequestHandler>(handleRequestFunction, std::move(config), concurrency);
106 return make_unique<FastcgiRequestHandler>(handleRequestFunction, std::move(config), concurrency);
109std::unique_ptr<RequestHandler>
112 return newRequestHandler(make_shared<HandleRequestFunctionWrapper>(std::move(handleRequestFunction)), std::move(config),
Response object to be passed back to NAWA and accessor to the request.
Class which connects NAWA to the fastcgi++ library.
A request handler which creates a development web server.
Handles and serves incoming requests via the NAWA app.
Class for managing sessions and getting and setting connection-independent session data.
bool applyFilters(AccessFilterList const &accessFilters)
virtual ~RequestHandler()
static std::unique_ptr< RequestHandler > newRequestHandler(std::shared_ptr< HandleRequestFunctionWrapper > const &handleRequestFunction, Config config, int concurrency)
void handleRequest(Connection &connection)
void reconfigure(std::optional< std::shared_ptr< HandleRequestFunctionWrapper > > handleRequestFunction, std::optional< AccessFilterList > accessFilters, std::optional< Config > config) noexcept
Namespace containing functions for text encoding and decoding.
#define NAWA_DEFAULT_CONSTRUCTOR_IMPL(Class)
std::function< int(nawa::Connection &)> HandleRequestFunction