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 WEB_HTTP_SERVER_REQUEST_H
43#define WEB_HTTP_SERVER_REQUEST_H
45#include "web/http/ConnectionState.h"
47#ifndef DOXYGEN_SHOULD_SKIP_THIS
49#include "web/http/CiStringMap.h"
58namespace web::http::
server {
70 const std::string&
get(
const std::string& key,
int i = 0)
const;
71 const std::string&
cookie(
const std::string& key)
const;
72 const std::string&
query(
const std::string& key)
const;
91 Request(
int status,
const std::string& reason =
"");
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#define APPLICATION(req, res)
static void atNextTick(const std::function< void(void)> &callBack)
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
SocketServer(Args &&... args)
const SocketServer & listen(const SocketAddress &localAddress, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
std::shared_ptr< SocketContextFactory > getSocketContextFactory() 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)
SocketServer(const std::function< void(SocketConnection *)> &onConnect, const std::function< void(SocketConnection *)> &onConnected, const std::function< void(SocketConnection *)> &onDisconnect, Args &&... args)
core::socket::Socket< typename SocketAcceptor::Config > Super
std::function< void(SocketConnection *)> & getOnDisconnect() const
const SocketServer & realListen(const std::function< void(const SocketAddress &, core::socket::State)> &onStatus, unsigned int tries, double retryTimeoutScale) const
std::function< void(SocketConnection *)> & getOnConnected() const
const SocketServer & setOnConnected(const std::function< void(SocketConnection *)> &onConnected, bool initialize=false) const
const SocketServer & setOnConnect(const std::function< void(SocketConnection *)> &onConnect, bool initialize=false) const
const SocketServer & listen(const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
std::shared_ptr< Context > sharedContext
typename SocketAcceptor::SocketConnection SocketConnection
SocketServer & setOnDisconnect(const std::function< void(SocketConnection *)> &onDisconnect, bool initialize=false)
std::function< void(SocketConnection *)> & getOnConnect() const
SocketContextFactoryT SocketContextFactory
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)
const SocketServer & listen(const SocketAddress &localAddress, int backlog, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
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
const Super & listen(const std::string &ipOrHostname, uint16_t port, int backlog, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
const Super & listen(uint16_t port, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
const Super & listen(uint16_t port, int backlog, const std::function< void(const SocketAddress &, core::socket::State)> &onStatus) const
const Super & listen(const std::string &ipOrHostname, 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
std::shared_ptr< SocketContextFactory > socketContextFactory
std::function< void(SocketConnection *)> onConnected
std::function< void(SocketConnection *)> onConnect
std::function< void(SocketConnection *)> onDisconnect
Context(const std::shared_ptr< SocketContextFactory > &socketContextFactory, std::function< void(SocketConnection *)> onConnect, std::function< void(SocketConnection *)> onConnected, std::function< void(SocketConnection *)> onDisconnect)