NAWA 0.9
Web Application Framework for C++
nawa::RequestHandler Class Referenceabstract

#include <nawa/RequestHandler/RequestHandler.h>

Inherited by nawa::FastcgiRequestHandler, and nawa::HttpRequestHandler.

Public Member Functions

virtual ~RequestHandler ()
 
void setAppRequestHandler (std::shared_ptr< HandleRequestFunctionWrapper > handleRequestFunction) noexcept
 
void setAccessFilters (AccessFilterList accessFilters) noexcept
 
std::shared_ptr< Config const > getConfig () const noexcept
 
void setConfig (Config config) noexcept
 
void reconfigure (std::optional< std::shared_ptr< HandleRequestFunctionWrapper > > handleRequestFunction, std::optional< AccessFilterList > accessFilters, std::optional< Config > config) noexcept
 
void reconfigure (HandleRequestFunction handleRequestFunction, std::optional< AccessFilterList > accessFilters, std::optional< Config > config) noexcept
 
virtual void start ()=0
 
virtual void stop () noexcept=0
 
virtual void terminate () noexcept=0
 
virtual void restart () noexcept
 
virtual void join () noexcept=0
 
void handleRequest (Connection &connection)
 

Static Public Member Functions

static std::unique_ptr< RequestHandlernewRequestHandler (std::shared_ptr< HandleRequestFunctionWrapper > const &handleRequestFunction, Config config, int concurrency)
 
static std::unique_ptr< RequestHandlernewRequestHandler (HandleRequestFunction handleRequestFunction, Config config, int concurrency)
 

Protected Member Functions

 RequestHandler ()
 

Detailed Description

Definition at line 36 of file RequestHandler.h.

Constructor & Destructor Documentation

◆ RequestHandler()

nawa::RequestHandler::RequestHandler ( )
protected

◆ ~RequestHandler()

RequestHandler::~RequestHandler ( )
virtual

The overridden virtual destructor must terminate request handling and join worker threads, if not yet done. It also removes all stored session data to avoid a segfault during shutdown.

Definition at line 116 of file RequestHandler.cpp.

Member Function Documentation

◆ newRequestHandler() [1/2]

std::unique_ptr< RequestHandler > RequestHandler::newRequestHandler ( std::shared_ptr< HandleRequestFunctionWrapper > const &  handleRequestFunction,
Config  config,
int  concurrency 
)
static

Create a new request handler object according to the config. May throw a nawa::Exception on failure (passed on from the constructor of the specific request handler). The constructor of a request handler should set up everything that's necessary already here (as the constructor is the only function of a request handler which is executed with full privileges).

Parameters
handleRequestFunctionA HandleRequestFunctionWrapper containing the handleRequest function of the app.
configThe config.
concurrencyConcurrency level (number of worker threads).
Returns
A unique_ptr to the request handler.

Definition at line 101 of file RequestHandler.cpp.

◆ newRequestHandler() [2/2]

std::unique_ptr< RequestHandler > RequestHandler::newRequestHandler ( HandleRequestFunction  handleRequestFunction,
Config  config,
int  concurrency 
)
static

Create a new request handler object according to the config. May throw a nawa::Exception on failure (passed on from the constructor of the specific request handler). The constructor of a request handler should set up everything that's necessary already here (as the constructor is the only function of a request handler which is executed with full privileges).

Parameters
handleRequestFunctionThe handleRequest function of the app.
configThe config.
concurrencyConcurrency level (number of worker threads).
Returns
A unique_ptr to the request handler.

Definition at line 110 of file RequestHandler.cpp.

◆ setAppRequestHandler()

void RequestHandler::setAppRequestHandler ( std::shared_ptr< HandleRequestFunctionWrapper handleRequestFunction)
noexcept

Set or replace the handleRequest function of the app (thread-safe, blocking).

Parameters
handleRequestFunctionThe request handling function of the app.
Deprecated:
Might be made private and non-blocking in v0.8 (or later), use reconfigure() instead.

Definition at line 45 of file RequestHandler.cpp.

◆ setAccessFilters()

void RequestHandler::setAccessFilters ( AccessFilterList  accessFilters)
noexcept

Set or replace access filters for static request filtering (thread-safe, blocking).

Parameters
accessFiltersThe access filters.

Definition at line 50 of file RequestHandler.cpp.

◆ getConfig()

std::shared_ptr< Config const > RequestHandler::getConfig ( ) const
noexcept

Get a pointer for reading the config.

Returns
Pointer to the config.

Definition at line 60 of file RequestHandler.cpp.

◆ setConfig()

void RequestHandler::setConfig ( Config  config)
noexcept

Set or replace the config (thread-safe, blocking).

Parameters
configThe config.
Deprecated:
Might be made private and non-blocking in v0.8 (or later), use reconfigure() instead.

Definition at line 55 of file RequestHandler.cpp.

◆ reconfigure() [1/2]

void nawa::RequestHandler::reconfigure ( std::optional< std::shared_ptr< HandleRequestFunctionWrapper > >  handleRequestFunction,
std::optional< AccessFilterList accessFilters,
std::optional< Config config 
)
noexcept

Reconfigure the request handler (thread-safe, blocking).

Parameters
handleRequestFunctionA HandleRequestFunctionWrapper containing the handleRequest function of the app.
accessFiltersThe access filters.
configThe config.

◆ reconfigure() [2/2]

void nawa::RequestHandler::reconfigure ( HandleRequestFunction  handleRequestFunction,
std::optional< AccessFilterList accessFilters,
std::optional< Config config 
)
noexcept

Reconfigure the request handler (thread-safe, blocking).

Parameters
handleRequestFunctionThe request handling function of the app.
accessFiltersThe access filters.
configThe config.

Definition at line 79 of file RequestHandler.cpp.

◆ start()

virtual void nawa::RequestHandler::start ( )
pure virtual

Start request handling. Must not block and return immediately if request handling is already running. May throw a nawa::Exception on failure during startup, but ideally, all actions which could lead to errors (or preliminary checks to avoid errors) should be done in the constructor, to avoid unnecessary initialization steps. Behavior of calling this function after join() has already been called is undefined, ideally, it should throw a nawa::Exception (proposed error code: 10). Please not that request handlers currently do NOT have to support restarting (i.e., calling stop, then start). The default FastCGI and HTTP request handlers do not support this and will not start request handling once again after stopping.

Implemented in nawa::FastcgiRequestHandler, and nawa::HttpRequestHandler.

◆ stop()

virtual void nawa::RequestHandler::stop ( )
pure virtualnoexcept

Stop request handling after current requests have been served. Must not block and return immediately after the shutdown has been initiated. Must do nothing if request handling has already stopped or even joined.

Implemented in nawa::FastcgiRequestHandler, and nawa::HttpRequestHandler.

◆ terminate()

virtual void nawa::RequestHandler::terminate ( )
pure virtualnoexcept

Enforce termination of request handling. Must not block and return immediately after the termination of request handling has been initiated (nevertheless, the termination should only take a few milliseconds after this function has been called). Must do nothing if request handling has already stopped or even joined.

Implemented in nawa::FastcgiRequestHandler, and nawa::HttpRequestHandler.

◆ restart()

virtual void nawa::RequestHandler::restart ( )
inlinevirtualnoexcept

Restart request handling. Can optionally be supported by request handlers (the default request handlers for FastCGI and HTTP currently do NOT support this). If unsupported, this function does not have to be implemented, and will just do nothing.

Definition at line 150 of file RequestHandler.h.

◆ join()

virtual void nawa::RequestHandler::join ( )
pure virtualnoexcept

Block until request handling has terminated. This is the only function that should block. If join has already been called, this function must return immediately, without throwing exceptions. By joining, the RequestHandler object becomes defunct and cannot be reused afterwards.

Implemented in nawa::FastcgiRequestHandler, and nawa::HttpRequestHandler.

◆ handleRequest()

void RequestHandler::handleRequest ( Connection connection)

Handle request by processing the filters and calling the app's handleRequest function, if necessary. Internal function which should only be used by request handlers.

Parameters
connectionThe current Connection object.

Definition at line 85 of file RequestHandler.cpp.


The documentation for this class was generated from the following files: