Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
sese::service::http::HttpServer Class Referencefinal

#include <HttpServer.h>

Public Member Functions

template<class CTL , class... ARGS>
void regController (ARGS &&...args)
 
void regMountPoint (const std::string &uri_prefix, const std::string &local)
 
void regFilter (const std::string &uri_prefix, const HttpService::FilterCallback &callback)
 
void regServlet (const net::http::Servlet &servlet)
 
void regTailFilter (const HttpService::FilterCallback &tail_filter)
 
void setKeepalive (uint32_t seconds)
 
void regService (const net::IPAddress::Ptr &address, std::unique_ptr< security::SSLContext > context)
 
void setName (const std::string &name)
 
void setConnectionCallback (const HttpService::ConnectionCallback &callback)
 
bool startup () const
 
bool shutdown () const
 

Private Attributes

std::string name
 
uint32_t keepalive = 5
 
std::vector< HttpService::Ptrservices
 
std::vector< net::http::Controller::Ptrcontrollers
 
HttpService::MountPointMap mount_points
 
HttpService::ServletMap servlets
 
HttpService::FilterMap filters
 
HttpService::FilterCallback tail_filter
 
HttpService::ConnectionCallback connection_callback
 

Detailed Description

HTTP Server

Note
Invocation priority: Filter > Mount Point (Filter) > Controller = Servlet, independent and non-convertible

Member Function Documentation

◆ regController()

template<class CTL , class... ARGS>
void sese::service::http::HttpServer::regController ( ARGS &&... args)

Register controller

Template Parameters
CTLController type
ARGSInstantiation parameter types
Parameters
argsInstantiation parameters

References controllers, and servlets.

◆ regFilter()

void HttpServer::regFilter ( const std::string & uri_prefix,
const HttpService::FilterCallback & callback )

Register filter

Parameters
uri_prefixURI prefix
callbackCallback function. If the function returns true, it needs further processing, i.e., continue to determine subsequent mount points, controllers, etc. Otherwise, intercept the current request and respond directly.

References callback(), and filters.

◆ regMountPoint()

void HttpServer::regMountPoint ( const std::string & uri_prefix,
const std::string & local )

Register file system mount point

Parameters
uri_prefixURI prefix
localLocal path

References mount_points.

◆ regService()

void HttpServer::regService ( const net::IPAddress::Ptr & address,
std::unique_ptr< security::SSLContext > context )

Register HTTP service

Parameters
addressListening address
contextSSL service context, if null, SSL is not enabled

References connection_callback, sese::service::http::HttpService::create(), filters, keepalive, mount_points, name, services, servlets, and tail_filter.

◆ regServlet()

void HttpServer::regServlet ( const net::http::Servlet & servlet)

Register HTTP application

Parameters
servletHTTP application

References sese::net::http::Servlet::getUri(), and servlets.

◆ regTailFilter()

void HttpServer::regTailFilter ( const HttpService::FilterCallback & tail_filter)

This method is used to register a post-processing filter that will be executed after other all servlets, controllers, and mount points process exceptions. If you need to finally modify or process the response (e.g., custom 404 pages), you can use this feature. The return value indicates whether the interception has been processed. After interception, the response type will change to Controller and accept the relevant processing.

Parameters
tail_filterThe post-processing HTTP filter to register, used to handle requests

References tail_filter.

◆ setConnectionCallback()

void HttpServer::setConnectionCallback ( const HttpService::ConnectionCallback & callback)

Set connection callback function, the function will be called before the connection object is created, and the SSL connection has not yet been established

Parameters
callbackConnection callback function. If the function returns true, normal processing will continue, otherwise the connection will be discarded directly.

References callback(), and connection_callback.

◆ setKeepalive()

void HttpServer::setKeepalive ( uint32_t seconds)

Set keepalive

Parameters
secondsKeepalive duration, minimum value is 5

References keepalive.

◆ setName()

void HttpServer::setName ( const std::string & name)

Set server name

Parameters
nameServer name

References name.

◆ shutdown()

bool HttpServer::shutdown ( ) const

Stop service

Returns
Result

References services.

◆ startup()

bool HttpServer::startup ( ) const

Start service

Returns
Result

References services, SESE_ERROR, and SESE_INFO.

Member Data Documentation

◆ connection_callback

HttpService::ConnectionCallback sese::service::http::HttpServer::connection_callback
private

◆ controllers

std::vector<net::http::Controller::Ptr> sese::service::http::HttpServer::controllers
private

Referenced by regController().

◆ filters

HttpService::FilterMap sese::service::http::HttpServer::filters
private

Referenced by regFilter(), and regService().

◆ keepalive

uint32_t sese::service::http::HttpServer::keepalive = 5
private

Referenced by regService(), and setKeepalive().

◆ mount_points

HttpService::MountPointMap sese::service::http::HttpServer::mount_points
private

Referenced by regMountPoint(), and regService().

◆ name

std::string sese::service::http::HttpServer::name
private

Referenced by regService(), and setName().

◆ services

std::vector<HttpService::Ptr> sese::service::http::HttpServer::services
private

Referenced by regService(), shutdown(), and startup().

◆ servlets

HttpService::ServletMap sese::service::http::HttpServer::servlets
private

◆ tail_filter

HttpService::FilterCallback sese::service::http::HttpServer::tail_filter
private

Referenced by regService(), and regTailFilter().


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