libcex
1.0.0
Modern C++11 embedded webserver library
|
Core class of the embedded webserver. Manages a single HTTP/HTTPS listener and performs routing as defined by the installed middlewares. More...
#include <core.hpp>
Classes | |
struct | Config |
Structure transporting all configuration options of the embedded server. Note that certain middlewares have additional config structs (e. g. cex::filesystem ) More... | |
struct | Context |
Internal helper struct for handling libevhtp callback functions. More... | |
Public Member Functions | |
Server () | |
Constructs a new server with the default config. | |
Server (Config &config) | |
Constructs a new server with the given config. More... | |
int | listen (bool block=true) |
Starts the server with listener on address and port specified in the server Config struct. More... | |
int | listen (std::string address, int port, bool block=true) |
Starts the server with listener on the given address and port. More... | |
int | stop () |
Stops the listener. If it was started within a background thread, the background thread is terminated. | |
void | reset () |
Removes all attached middlewares. | |
void | use (MiddlewareFunction func) |
Attaches a middleware function with no conditions. More... | |
void | use (const char *path, MiddlewareFunction func, int flags=Middleware::fMatchContain) |
Attaches a middleware function with no HTTP method specification and with the given path. More... | |
void | get (MiddlewareFunction func) |
Attaches a middleware function for HTTP GET requests. More... | |
void | get (const char *path, MiddlewareFunction func, int flags=Middleware::fMatchContain) |
Attaches a middleware function for the HTTP GET method and the given path. More... | |
void | put (MiddlewareFunction func) |
Attaches a middleware function for HTTP PUT requests. More... | |
void | put (const char *path, MiddlewareFunction func, int flags=Middleware::fMatchContain) |
Attaches a middleware function for the HTTP PUT method and the given path. More... | |
void | post (MiddlewareFunction func) |
Attaches a middleware function for HTTP POST requests. More... | |
void | post (const char *path, MiddlewareFunction func, int flags=Middleware::fMatchContain) |
Attaches a middleware function for the HTTP POST method and the given path. More... | |
void | head (MiddlewareFunction func) |
Attaches a middleware function for HTTP HEAD requests. More... | |
void | head (const char *path, MiddlewareFunction func, int flags=Middleware::fMatchContain) |
Attaches a middleware function for the HTTP HEAD method and the given path. More... | |
void | del (MiddlewareFunction func) |
Attaches a middleware function for HTTP DEL requests. More... | |
void | del (const char *path, MiddlewareFunction func, int flags=Middleware::fMatchContain) |
Attaches a middleware function for the HTTP DEL method and the given path. More... | |
void | connect (MiddlewareFunction func) |
Attaches a middleware function for HTTP CONNECT requests. More... | |
void | connect (const char *path, MiddlewareFunction func, int flags=Middleware::fMatchContain) |
Attaches a middleware function for the HTTP CONNECT method and the given path. More... | |
void | options (MiddlewareFunction func) |
Attaches a middleware function for HTTP OPTIONS requests. More... | |
void | options (const char *path, MiddlewareFunction func, int flags=Middleware::fMatchContain) |
Attaches a middleware function for the HTTP OPTIONS method and the given path. More... | |
void | trace (MiddlewareFunction func) |
Attaches a middleware function for HTTP TRACE requests. More... | |
void | trace (const char *path, MiddlewareFunction func, int flags=Middleware::fMatchContain) |
Attaches a middleware function for the HTTP TRACE method and the given path. More... | |
void | patch (MiddlewareFunction func) |
Attaches a middleware function for HTTP PATCH requests. More... | |
void | patch (const char *path, MiddlewareFunction func, int flags=Middleware::fMatchContain) |
Attaches a middleware function for the HTTP PATCH method and the given path. More... | |
void | mkcol (MiddlewareFunction func) |
Attaches a middleware function for WEBDAV MKCOL requests. More... | |
void | mkcol (const char *path, MiddlewareFunction func, int flags=Middleware::fMatchContain) |
Attaches a middleware function for the WEBDAV MKCOL method and the given path. More... | |
void | copy (MiddlewareFunction func) |
Attaches a middleware function for WEBDAV COPY requests. More... | |
void | copy (const char *path, MiddlewareFunction func, int flags=Middleware::fMatchContain) |
Attaches a middleware function for the WEBDAV COPY method and the given path. More... | |
void | move (MiddlewareFunction func) |
Attaches a middleware function for WEBDAV MOVE requests. More... | |
void | move (const char *path, MiddlewareFunction func, int flags=Middleware::fMatchContain) |
Attaches a middleware function for the WEBDAV MOVE method and the given path. More... | |
void | propfind (MiddlewareFunction func) |
Attaches a middleware function for HTTP WEBDAV PROPFIND requests. More... | |
void | propfind (const char *path, MiddlewareFunction func, int flags=Middleware::fMatchContain) |
Attaches a middleware function for the WEBDAV PROPFIND method and the given path. More... | |
void | proppatch (MiddlewareFunction func) |
Attaches a middleware function for WEBDAV PROPPATCH requests. More... | |
void | proppatch (const char *path, MiddlewareFunction func, int flags=Middleware::fMatchContain) |
Attaches a middleware function for the WEBDAV PROPPATCH method and the given path. More... | |
void | lock (MiddlewareFunction func) |
Attaches a middleware function for WEBDAV LOCK requests. More... | |
void | lock (const char *path, MiddlewareFunction func, int flags=Middleware::fMatchContain) |
Attaches a middleware function for the WEBDAV LOCK method and the given path. More... | |
void | unlock (MiddlewareFunction func) |
Attaches a middleware function for WEBDAV UNLOCK requests. More... | |
void | unlock (const char *path, MiddlewareFunction func, int flags=Middleware::fMatchContain) |
Attaches a middleware function for the WEBDAV UNLOCK method and the given path. More... | |
void | uploads (UploadFunction func) |
Attaches a special middleware function which receives request body data uploads in chunks. More... | |
void | uploads (const char *path, UploadFunction func, Method method=methodPOST, int flags=Middleware::fMatchContain) |
Attaches an upload middleware function for the given HTTP method and URL path. More... | |
Static Public Member Functions | |
static MimeTypes * | getMimeTypes () |
static void | registerMimeType (const char *ext, const char *mime, bool binary) |
static void | libraryInit () |
Core class of the embedded webserver. Manages a single HTTP/HTTPS listener and performs routing as defined by the installed middlewares.
cex::Server::Server | ( | Config & | config | ) |
Constructs a new server with the given config.
config | The Config object which defines the server options/configuration |
void cex::Server::connect | ( | MiddlewareFunction | func | ) |
Attaches a middleware function for HTTP CONNECT requests.
The function will be called for every request.
func | The middleware function which shall be called |
void cex::Server::connect | ( | const char * | path, |
MiddlewareFunction | func, | ||
int | flags = Middleware::fMatchContain |
||
) |
Attaches a middleware function for the HTTP CONNECT method and the given path.
The function will be called when the URL of incoming requests match the path, regardless of HTTP method.
path | The URL path which shall be compared against the request URL |
func | The middleware function which shall be called |
flags | Flags controlling the URL matching behaviour (see Middleware) |
void cex::Server::copy | ( | MiddlewareFunction | func | ) |
Attaches a middleware function for WEBDAV COPY requests.
The function will be called for every request.
func | The middleware function which shall be called |
void cex::Server::copy | ( | const char * | path, |
MiddlewareFunction | func, | ||
int | flags = Middleware::fMatchContain |
||
) |
Attaches a middleware function for the WEBDAV COPY method and the given path.
The function will be called when the URL of incoming requests match the path, regardless of HTTP method.
path | The URL path which shall be compared against the request URL |
func | The middleware function which shall be called |
flags | Flags controlling the URL matching behaviour (see Middleware) |
void cex::Server::del | ( | MiddlewareFunction | func | ) |
Attaches a middleware function for HTTP DEL requests.
The function will be called for every request.
func | The middleware function which shall be called |
void cex::Server::del | ( | const char * | path, |
MiddlewareFunction | func, | ||
int | flags = Middleware::fMatchContain |
||
) |
Attaches a middleware function for the HTTP DEL method and the given path.
The function will be called when the URL of incoming requests match the path, regardless of HTTP method.
path | The URL path which shall be compared against the request URL |
func | The middleware function which shall be called |
flags | Flags controlling the URL matching behaviour (see Middleware) |
void cex::Server::get | ( | MiddlewareFunction | func | ) |
Attaches a middleware function for HTTP GET requests.
The function will be called for every request.
func | The middleware function which shall be called |
void cex::Server::get | ( | const char * | path, |
MiddlewareFunction | func, | ||
int | flags = Middleware::fMatchContain |
||
) |
Attaches a middleware function for the HTTP GET method and the given path.
The function will be called when the URL of incoming requests match the path, regardless of HTTP method.
path | The URL path which shall be compared against the request URL |
func | The middleware function which shall be called |
flags | Flags controlling the URL matching behaviour (see Middleware) |
void cex::Server::head | ( | MiddlewareFunction | func | ) |
Attaches a middleware function for HTTP HEAD requests.
The function will be called for every request.
func | The middleware function which shall be called |
void cex::Server::head | ( | const char * | path, |
MiddlewareFunction | func, | ||
int | flags = Middleware::fMatchContain |
||
) |
Attaches a middleware function for the HTTP HEAD method and the given path.
The function will be called when the URL of incoming requests match the path, regardless of HTTP method.
path | The URL path which shall be compared against the request URL |
func | The middleware function which shall be called |
flags | Flags controlling the URL matching behaviour (see Middleware) |
int cex::Server::listen | ( | bool | block = true | ) |
Starts the server with listener on address and port specified in the server Config struct.
block | If set to true , runs the listener/eventloop in the calling thread, thus blocking the caller. If set to false , spawns a new thread which runs the listener/eventloop, and returns immediately. |
int cex::Server::listen | ( | std::string | address, |
int | port, | ||
bool | block = true |
||
) |
Starts the server with listener on the given address and port.
address | The address to start the listener on (e.g. localhost or 10.0.2.14 ) |
port | The port to start the listener on |
block | If set to true , runs the listener/eventloop in the calling thread, thus blocking the caller. If set to false , spawns a new thread which runs the listener/eventloop, and returns immediately. |
void cex::Server::lock | ( | MiddlewareFunction | func | ) |
Attaches a middleware function for WEBDAV LOCK requests.
The function will be called for every request.
func | The middleware function which shall be called |
void cex::Server::lock | ( | const char * | path, |
MiddlewareFunction | func, | ||
int | flags = Middleware::fMatchContain |
||
) |
Attaches a middleware function for the WEBDAV LOCK method and the given path.
The function will be called when the URL of incoming requests match the path, regardless of HTTP method.
path | The URL path which shall be compared against the request URL |
func | The middleware function which shall be called |
flags | Flags controlling the URL matching behaviour (see Middleware) |
void cex::Server::mkcol | ( | MiddlewareFunction | func | ) |
Attaches a middleware function for WEBDAV MKCOL requests.
The function will be called for every request.
func | The middleware function which shall be called |
void cex::Server::mkcol | ( | const char * | path, |
MiddlewareFunction | func, | ||
int | flags = Middleware::fMatchContain |
||
) |
Attaches a middleware function for the WEBDAV MKCOL method and the given path.
The function will be called when the URL of incoming requests match the path, regardless of HTTP method.
path | The URL path which shall be compared against the request URL |
func | The middleware function which shall be called |
flags | Flags controlling the URL matching behaviour (see Middleware) |
void cex::Server::move | ( | MiddlewareFunction | func | ) |
Attaches a middleware function for WEBDAV MOVE requests.
The function will be called for every request.
func | The middleware function which shall be called |
void cex::Server::move | ( | const char * | path, |
MiddlewareFunction | func, | ||
int | flags = Middleware::fMatchContain |
||
) |
Attaches a middleware function for the WEBDAV MOVE method and the given path.
The function will be called when the URL of incoming requests match the path, regardless of HTTP method.
path | The URL path which shall be compared against the request URL |
func | The middleware function which shall be called |
flags | Flags controlling the URL matching behaviour (see Middleware) |
void cex::Server::options | ( | MiddlewareFunction | func | ) |
Attaches a middleware function for HTTP OPTIONS requests.
The function will be called for every request.
func | The middleware function which shall be called |
void cex::Server::options | ( | const char * | path, |
MiddlewareFunction | func, | ||
int | flags = Middleware::fMatchContain |
||
) |
Attaches a middleware function for the HTTP OPTIONS method and the given path.
The function will be called when the URL of incoming requests match the path, regardless of HTTP method.
path | The URL path which shall be compared against the request URL |
func | The middleware function which shall be called |
flags | Flags controlling the URL matching behaviour (see Middleware) |
void cex::Server::patch | ( | MiddlewareFunction | func | ) |
Attaches a middleware function for HTTP PATCH requests.
The function will be called for every request.
func | The middleware function which shall be called |
void cex::Server::patch | ( | const char * | path, |
MiddlewareFunction | func, | ||
int | flags = Middleware::fMatchContain |
||
) |
Attaches a middleware function for the HTTP PATCH method and the given path.
The function will be called when the URL of incoming requests match the path, regardless of HTTP method.
path | The URL path which shall be compared against the request URL |
func | The middleware function which shall be called |
flags | Flags controlling the URL matching behaviour (see Middleware) |
void cex::Server::post | ( | MiddlewareFunction | func | ) |
Attaches a middleware function for HTTP POST requests.
The function will be called for every request.
func | The middleware function which shall be called |
void cex::Server::post | ( | const char * | path, |
MiddlewareFunction | func, | ||
int | flags = Middleware::fMatchContain |
||
) |
Attaches a middleware function for the HTTP POST method and the given path.
The function will be called when the URL of incoming requests match the path, regardless of HTTP method.
path | The URL path which shall be compared against the request URL |
func | The middleware function which shall be called |
flags | Flags controlling the URL matching behaviour (see Middleware) |
void cex::Server::propfind | ( | MiddlewareFunction | func | ) |
Attaches a middleware function for HTTP WEBDAV PROPFIND requests.
The function will be called for every request.
func | The middleware function which shall be called |
void cex::Server::propfind | ( | const char * | path, |
MiddlewareFunction | func, | ||
int | flags = Middleware::fMatchContain |
||
) |
Attaches a middleware function for the WEBDAV PROPFIND method and the given path.
The function will be called when the URL of incoming requests match the path, regardless of HTTP method.
path | The URL path which shall be compared against the request URL |
func | The middleware function which shall be called |
flags | Flags controlling the URL matching behaviour (see Middleware) |
void cex::Server::proppatch | ( | MiddlewareFunction | func | ) |
Attaches a middleware function for WEBDAV PROPPATCH requests.
The function will be called for every request.
func | The middleware function which shall be called |
void cex::Server::proppatch | ( | const char * | path, |
MiddlewareFunction | func, | ||
int | flags = Middleware::fMatchContain |
||
) |
Attaches a middleware function for the WEBDAV PROPPATCH method and the given path.
The function will be called when the URL of incoming requests match the path, regardless of HTTP method.
path | The URL path which shall be compared against the request URL |
func | The middleware function which shall be called |
flags | Flags controlling the URL matching behaviour (see Middleware) |
void cex::Server::put | ( | MiddlewareFunction | func | ) |
Attaches a middleware function for HTTP PUT requests.
The function will be called for every request.
func | The middleware function which shall be called |
void cex::Server::put | ( | const char * | path, |
MiddlewareFunction | func, | ||
int | flags = Middleware::fMatchContain |
||
) |
Attaches a middleware function for the HTTP PUT method and the given path.
The function will be called when the URL of incoming requests match the path, regardless of HTTP method.
path | The URL path which shall be compared against the request URL |
func | The middleware function which shall be called |
flags | Flags controlling the URL matching behaviour (see Middleware) |
void cex::Server::trace | ( | MiddlewareFunction | func | ) |
Attaches a middleware function for HTTP TRACE requests.
The function will be called for every request.
func | The middleware function which shall be called |
void cex::Server::trace | ( | const char * | path, |
MiddlewareFunction | func, | ||
int | flags = Middleware::fMatchContain |
||
) |
Attaches a middleware function for the HTTP TRACE method and the given path.
The function will be called when the URL of incoming requests match the path, regardless of HTTP method.
path | The URL path which shall be compared against the request URL |
func | The middleware function which shall be called |
flags | Flags controlling the URL matching behaviour (see Middleware) |
void cex::Server::unlock | ( | MiddlewareFunction | func | ) |
Attaches a middleware function for WEBDAV UNLOCK requests.
The function will be called for every request.
func | The middleware function which shall be called |
void cex::Server::unlock | ( | const char * | path, |
MiddlewareFunction | func, | ||
int | flags = Middleware::fMatchContain |
||
) |
Attaches a middleware function for the WEBDAV UNLOCK method and the given path.
The function will be called when the URL of incoming requests match the path, regardless of HTTP method.
path | The URL path which shall be compared against the request URL |
func | The middleware function which shall be called |
flags | Flags controlling the URL matching behaviour (see Middleware) |
void cex::Server::uploads | ( | UploadFunction | func | ) |
Attaches a special middleware function which receives request body data uploads in chunks.
The provided UploadFunction will be called repeatedly until the whole request body data is received. Processing will not continue to any subsequent middlewares until the upload is completed.
func | The UploadFunction which shall be called upon receiving request body data |
void cex::Server::uploads | ( | const char * | path, |
UploadFunction | func, | ||
Method | method = methodPOST , |
||
int | flags = Middleware::fMatchContain |
||
) |
Attaches an upload middleware function for the given HTTP method and URL path.
The provided UploadFunction will be called repeatedly for matching requests until the whole request body data is received. Processing will not continue to any subsequent middlewares until the upload is completed.
path | The URL path which shall be compared against the request URL |
func | The UploadFunction which shall be called upon receiving request body data |
flags | Flags controlling the URL matching behaviour (see Middleware) |
void cex::Server::use | ( | MiddlewareFunction | func | ) |
Attaches a middleware function with no conditions.
The function will be called for every request.
func | The middleware function which shall be called |
void cex::Server::use | ( | const char * | path, |
MiddlewareFunction | func, | ||
int | flags = Middleware::fMatchContain |
||
) |
Attaches a middleware function with no HTTP method specification and with the given path.
The function will be called when the URL of incoming requests match the path, regardless of HTTP method.
path | The URL path which shall be compared against the request URL |
func | The middleware function which shall be called |
flags | Flags controlling the URL matching behaviour (see Middleware) |