2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
42#ifndef EXPRESS_MIDDLEWARE_JSONMIDDLEWARE_H
43#define EXPRESS_MIDDLEWARE_JSONMIDDLEWARE_H
45#include "express/Router.h"
47#ifndef DOXYGEN_SHOULD_SKIP_THIS
51namespace express::middleware {
53 class JsonMiddleware :
public Router {
55 JsonMiddleware(
const JsonMiddleware&) =
delete;
57 JsonMiddleware& operator=(
const JsonMiddleware&) =
delete;
62 static class JsonMiddleware& instance();
65 friend class JsonMiddleware& JsonMiddleware();
68 class JsonMiddleware& JsonMiddleware();
#define APPLICATION(req, res)
virtual void acceptTimeout()
void signalEvent(int signum) override
AcceptEventReceiver(const std::string &name, const utils::Timeval &timeout)
virtual void acceptEvent()=0
void dispatchEvent() final
void timeoutEvent() final
Config & getConfig() const
State & operator&=(int state)
static constexpr int DISABLED
bool operator==(const int &state) const
State operator&(int state)
static constexpr int ERROR
static constexpr int FATAL
static constexpr int NO_RETRY
std::function< void(SocketConnection *)> onConnected
SocketConnectionT< PhysicalServerSocket, Config > SocketConnection
PhysicalSocketServerT PhysicalServerSocket
SocketAcceptor(const SocketAcceptor &socketAcceptor)
SocketAddress bindAddress
std::function< void(SocketConnection *)> onConnect
std::function< void(SocketConnection *)> onDisconnect
void unobservedEvent() final
std::shared_ptr< Config > config
virtual void useNextSocketAddress()=0
typename PhysicalServerSocket::SocketAddress SocketAddress
SocketAcceptor(const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus, const std::shared_ptr< Config > &config)
~SocketAcceptor() override
PhysicalServerSocket physicalServerSocket
std::function< void(const SocketAddress &, core::socket::State)> onStatus
SocketAcceptorT SocketAcceptor
std::function< void(SocketConnection *)> & getOnConnect()
std::function< void(SocketConnection *)> setOnConnected(const std::function< void(SocketConnection *)> &onConnected, bool initialize=false)
SocketServer(Args &&... args)
void realListen(const std::function< void(const SocketAddress &, core::socket::State)> &onStatus, unsigned int tries, double retryTimeoutScale) const
SocketServer(const std::string &name, const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, Args &&... args)
typename SocketAcceptor::SocketAddress SocketAddress
SocketServer(const std::string &name, Args &&... args)
std::function< void(SocketConnection *)> onConnect
SocketServer(const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, Args &&... args)
std::function< void(SocketConnection *)> setOnConnect(const std::function< void(SocketConnection *)> &onConnect, bool initialize=false)
std::function< void(SocketConnection *)> & getOnDisconnect()
core::socket::Socket< typename SocketAcceptor::Config > Super
std::function< void(SocketConnection *)> setOnDisconnect(const std::function< void(SocketConnection *)> &onDisconnect, bool initialize=false)
std::function< void(SocketConnection *)> onDisconnect
void listen(const SocketAddress &localAddress, int backlog, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
void listen(const SocketAddress &localAddress, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
std::shared_ptr< SocketContextFactory > socketContextFactory
void listen(const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
std::function< void(SocketConnection *)> onConnected
typename SocketAcceptor::SocketConnection SocketConnection
std::function< void(SocketConnection *)> & getOnConnected()
SocketContextFactoryT SocketContextFactory
std::shared_ptr< SocketContextFactory > getSocketContextFactory()
SocketServer(const std::shared_ptr< Config > &config, const std::shared_ptr< SocketContextFactory > &socketContextFactory, const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect)
typename SocketAcceptor::Config Config
void useNextSocketAddress() override
typename Super::Config Config
typename Super::SocketAddress SocketAddress
typename Super::SocketConnection SocketConnection
core::socket::stream::SocketAcceptor< PhysicalServerSocketT, ConfigT, core::socket::stream::legacy::SocketConnection > Super
SocketAcceptor(const SocketAcceptor &socketAcceptor)
SocketAcceptor(const std::shared_ptr< core::socket::stream::SocketContextFactory > &socketContextFactory, const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus, const std::shared_ptr< Config > &config)
static Timer singleshotTimer(const std::function< void()> &dispatcher, const utils::Timeval &timeout)
Controller(const std::shared_ptr< web::http::server::Request > &request, const std::shared_ptr< web::http::server::Response > &response)
void send(const std::string &chunk)
WebAppT(const std::string &name, const Router &router)
typename Server::SocketConnection SocketConnection
express::Response Response
typename Server::SocketAddress SocketAddress
WebAppT(const std::string &name)
static void init(int argc, char *argv[])
static core::TickStatus tick(const utils::Timeval &timeOut=0)
static core::State state()
static int start(const utils::Timeval &timeOut={LONG_MAX, 0})
WebApp(const Router &router)
const std::string & getInstanceName() const
ConfigPhysicalSocketServer(ConfigInstance *instance)
utils::Timeval getAcceptTimeout() const
CLI::Option * acceptTimeoutOpt
ConfigPhysicalSocketServer & setAcceptTimeout(const utils::Timeval &acceptTimeout)
CLI::Option * acceptsPerTickOpt
ConfigPhysicalSocketServer & setBacklog(int newBacklog)
int getAcceptsPerTick() const
ConfigPhysicalSocketServer Socket
ConfigPhysicalSocket Super
ConfigPhysicalSocketServer & setAcceptsPerTick(int acceptsPerTickSet)
ConfigAddressRemoteT< net::config::ConfigAddressReverse > Remote
ConfigSocketServer(net::config::ConfigInstance *instance)
ConfigAddressLocalT< net::config::ConfigAddressLocal > Local
ConfigSocketServer(const std::string &name)
std::string toString(bool expanded=true) const override
PhysicalSocketServer(PhysicalSocketServer &&) noexcept=default
net::in::phy::stream::PhysicalSocket< net::phy::stream::PhysicalSocketServer > Super
~PhysicalSocketServer() override
void listen(const std::string &ipOrHostname, uint16_t port, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
void listen(uint16_t port, int backlog, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
void listen(const std::string &ipOrHostname, uint16_t port, int backlog, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
void listen(uint16_t port, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
core::socket::stream:: SocketServer< SocketAcceptorT< net::in::phy::stream::PhysicalSocketServer, ConfigSocketServerT >, SocketContextFactoryT, Args... > Super
~ConfigSocketServer() override
CLI::Option * disableNagleAlgorithmOpt
bool getReusePort() const
ConfigSocketServer & setReusePort(bool reusePort=true)
bool getReuseAddress() const
bool getDisableNagleAlgorithm() const
ConfigSocketServer & setReuseAddress(bool reuseAddress=true)
ConfigSocketServer(net::config::ConfigInstance *instance)
CLI::Option * reusePortOpt
ConfigSocketServer & setDisableNagleAlgorithm(bool disableNagleAlgorithm=true)
CLI::Option * reuseAddressOpt
~ConfigSocketServer() override
ConfigSocketServer(const std::string &name)
net::phy::stream::PhysicalSocket< SocketAddressT > Super
SocketAddressT SocketAddress
void getAttribute(const std::function< void(Attribute &)> &onFound, const std::function< void(const std::string &)> &onNotFound, const std::string &subKey="") const
static double getInRange(double ll, double ul)
Timeval(const std::initializer_list< time_t > &initList) noexcept
RequestParser & operator=(const RequestParser &)=delete
void parsingFinished() override
void parseStartLine(const std::string &line) override
void parseError(int code, const std::string &reason) override
std::function< void(int, const std::string &)> onRequestParseError
std::function< void(Request &&)> onRequestParsed
std::set< std::string > supportedMethods
virtual bool methodSupported(const std::string &method) const
void analyzeHeader() override
RequestParser(const RequestParser &)=delete
std::function< void()> onRequestStart
RequestParser(core::socket::stream::SocketContext *socketContext, const std::function< void()> &onRequestStart, const std::function< void(Request &&)> &onRequestParsed, const std::function< void(int, const std::string &)> &onRequestParseError)
Request & operator=(Request &&) noexcept=delete
CiStringMap< std::string > cookies
const std::string & query(const std::string &key) const
CiStringMap< std::string > headers
Request(Request &&) noexcept=default
Request(int status, const std::string &reason="")
const std::string & cookie(const std::string &key) const
CiStringMap< std::string > queries
const std::string & get(const std::string &key, int i=0) const
Request(Request &)=delete
ConnectionState connectionState
Request & operator=(Request &)=delete
Server(const std::string &name, std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &&onRequestReady)
Server(const std::string &name, const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &&onRequestReady)
SocketServerT< web::http::server::SocketContextFactory, std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> > Super
typename SocketConnection::SocketAddress SocketAddress
Server(const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &&onRequestReady)
Server(const std::function< void(const std::shared_ptr< Request > &, std::shared_ptr< Response > &)> &&onRequestReady)
web::http::server::Request Request
web::http::server::Response Response
typename Super::SocketConnection SocketConnection
std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> onRequestReady
core::socket::stream::SocketContext * create(core::socket::stream::SocketConnection *socketConnection) override
web::http::server::Request Request
web::http::server::Response Response
SocketContextFactory(const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &onRequestReady)
bool onSignal(int signum) override
std::list< std::function< void()> > onDisconnectEventReceiverList
void onConnected() override
void onDisconnected() override
void responseCompleted(const Response &response, bool success)
std::shared_ptr< Response > masterResponse
core::socket::stream::SocketContext Super
web::http::server::Response Response
std::size_t onReceivedFromPeer() override
void onWriteError(int errnum) override
std::list< std::function< void()> > onConnectEventReceiverList
void responseStarted(const Response &response)
void requestCompleted(const Response &response)
SocketContext(core::socket::stream::SocketConnection *socketConnection, const std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> &onRequestReady)
std::function< void(const std::shared_ptr< Request > &, const std::shared_ptr< Response > &)> onRequestReady
web::http::server::Request Request
SocketContext * onConnected(std::function< void()> onConnectEventReceiver)
SocketContext * onDisconnected(std::function< void()> onDisconnectEventReceiver)
std::list< std::shared_ptr< Request > > pendingRequests
int main(int argc, char *argv[])
SocketServer Server(const std::string &instanceName, const std::function< void(typename SocketServer::Config &)> &configurator, Args &&... socketContextFactoryArgs)
SocketServer Server(const std::string &instanceName, Args &&... socketContextFactoryArgs)
SocketServer< SocketContextFactory, SocketContextFactoryArgs... > Server(const std::string &instanceName, const std::function< void(typename SocketServer< SocketContextFactory, SocketContextFactoryArgs... >::Config &)> &configurator, SocketContextFactoryArgs &&... socketContextFactoryArgs)
SocketServer< SocketContextFactory, SocketContextFactoryArgs... > Server(const std::string &instanceName, SocketContextFactoryArgs &&... socketContextFactoryArgs)
net::in::stream::SocketServer< core::socket::stream::legacy::SocketAcceptor, net::in::stream::legacy::config::ConfigSocketServer, SocketContextFactoryT, Args... > SocketServer
web::http::server::Server< net::in::stream::legacy::SocketServer > Server