tufao
0.8.1
An asynchronous web framework for C++ built on top of Qt
|
The Tufao::HttpServer class provides an implementation of the HTTP protocol. 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 | setHttpUpgradeRouter (HttpUpgradeRouter *router) |
Sets the HttpUpgradeRouter used to handle HTTP upgrades. 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... | |
virtual void | upgrade (HttpServerRequest *request, const QByteArray &head) |
This virtual function is called by HttpServer when a client requests a http upgrade. 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.
|
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.
|
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::setHttpUpgradeRouter | ( | HttpUpgradeRouter * | router | ) |
Sets the HttpUpgradeRouter used to handle HTTP upgrades.
The default behaviour is use none routers to handle HTTP upgrades. If you add any router, then the default behaviour will be to use this router, but the default behaviour still can be changed if you override the upgrade method.
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).
|
protectedvirtual |
This virtual function is called by HttpServer when a client requests a http upgrade.
The base implementation closes the connection if no upgrade router is configured or the upgrade router isn't able to handle the request.
Reimplement this function to alter the server's behavior when a http upgrade is requested.
request
object is deleted.request
(Tufao::HttpServerRequest::socket) will be deleted when disconnected. If you need to delete it sooner, just call QIODevice::close or QObject::deleteLater.