tufao
1.3.0
An asynchronous web framework for C++ built on top of Qt
|
The Tufao::HttpServer class provides an implementation of the HTTP protocol. More...
Public Types | |
typedef std::function< void(HttpServerRequest &request, const QByteArray &)> | UpgradeHandler |
A typedef to http upgrade request handler. More... | |
Public Slots | |
void | close () |
Closes the server. More... | |
Signals | |
void | requestReady (Tufao::HttpServerRequest &request, Tufao::HttpServerResponse &response) |
This signal is emitted each time there is request. More... | |
Public Member Functions | |
HttpServer (QObject *parent=0) | |
Constructs a Tufao::HttpServer object. More... | |
~HttpServer () | |
Destroys the object. | |
bool | listen (const QHostAddress &address=QHostAddress::Any, quint16 port=0) |
Tells the server to listen for incoming connections on address address and port port . More... | |
bool | isListening () const |
Returns true if the server is listening for incoming connections. | |
quint16 | serverPort () const |
Returns the server's port if the server is listening; otherwise returns 0. More... | |
void | setTimeout (int msecs=0) |
Sets the timeout of new connections to msecs miliseconds. More... | |
int | timeout () const |
Returns the current set timeout. | |
void | setUpgradeHandler (UpgradeHandler functor) |
This method sets the handler that will be called to handle http upgrade requests. More... | |
Static Public Member Functions | |
static UpgradeHandler | defaultUpgradeHandler () |
Returns the default http upgrade request's handler. More... | |
Protected Member Functions | |
void | handleConnection (QAbstractSocket *connection) |
Call this function will make Tufao::HttpServer handle the connection connection . More... | |
virtual void | incomingConnection (qintptr socketDescriptor) |
This virtual function is called by HttpServer when a new connection is available. More... | |
virtual void | checkContinue (HttpServerRequest &request, HttpServerResponse &response) |
This virtual function is called by HttpServer when a client do a request with the HTTP header "Expect: 100-continue". More... | |
The Tufao::HttpServer class provides an implementation of the HTTP protocol.
The HTTP is a stateless request-response based protoccol. It let you create distributed dynamic collaborative applications.
To create a webserver, all you need to do is call Tufao::HttpServer::listen and handle the Tufao::HttpServer::requestReady signal.
typedef std::function<void(HttpServerRequest &request, const QByteArray&)> Tufao::HttpServer::UpgradeHandler |
A typedef to http upgrade request handler.
|
explicit |
Constructs a Tufao::HttpServer object.
parent
is passed to the QObject constructor.
|
protectedvirtual |
This virtual function is called by HttpServer when a client do a request with the HTTP header "Expect: 100-continue".
The base implementation call Tufao::HttpServerRequest::writeContinue and emit the Tufao::HttpServer::requestReady signal.
Reimplement this function to alter the server's behavior when a "Expect: 100-continue" request is received.
|
slot |
Closes the server.
The server will no longer listen for incoming connections.
|
static |
Returns the default http upgrade request's handler.
The default handler closes the connection.
|
protected |
Call this function will make Tufao::HttpServer handle the connection connection
.
The Tufao::HttpServer object will take ownership of the connection
object and delete it when appropriate.
|
protectedvirtual |
This virtual function is called by HttpServer when a new connection is available.
The base implementation creates a QTcpSocket, sets the socket descriptor and call Tufao::HttpServer::handleConnection.
Reimplement this function to alter the server's behavior when a connection is available.
bool Tufao::HttpServer::listen | ( | const QHostAddress & | address = QHostAddress::Any , |
quint16 | port = 0 |
||
) |
Tells the server to listen for incoming connections on address address
and port port
.
If port
is 0, a port is chosen automatically. The default registered port to HTTP server is 80.
If address
is QHostAddress::Any, the server will listen on all network interfaces.
|
signal |
This signal is emitted each time there is request.
request
objects, so you can't, as an example, create a map using request
as key to identify sessions.request
and response
. request
and response
are deleted when the connection closes. Additionally, response
will also be deleted when you are done with it (eg., calling Tufao::HttpServerResponse::end).request | An instance of Tufao::HttpServerRequest |
response | An instance of Tufao::HttpServerResponse |
quint16 Tufao::HttpServer::serverPort | ( | ) | const |
Returns the server's port if the server is listening; otherwise returns 0.
void Tufao::HttpServer::setTimeout | ( | int | msecs = 0 | ) |
Sets the timeout of new connections to msecs
miliseconds.
If you set the timeout to 0, then timeout feature will be disabled. You should NOT disable this feature to help to protect against DoS attacks.
The default timeout is 2 minutes (120000 miliseconds).
void Tufao::HttpServer::setUpgradeHandler | ( | UpgradeHandler | functor | ) |
This method sets the handler that will be called to handle http upgrade requests.