tufao
0.8.1
An asynchronous web framework for C++ built on top of Qt
|
You can use this class to serve static files under Tufão. More...
Public Slots | |
bool | handleRequest (Tufao::HttpServerRequest *request, Tufao::HttpServerResponse *response, const QStringList &=QStringList()) |
It searchs for the file requested in the root dir and respond to the request, if the file is found. More... | |
Public Slots inherited from Tufao::AbstractHttpServerRequestHandler | |
virtual bool | handleRequest (Tufao::HttpServerRequest *request, Tufao::HttpServerResponse *response, const QStringList &args=QStringList())=0 |
Handles the request using the response object. More... | |
Public Member Functions | |
HttpFileServer (const QString &dir, QObject *parent=0) | |
Constructs a HttpFileServer object. More... | |
~HttpFileServer () | |
Destroys the object. | |
void | setDir (const QString &dir) |
Set the root dir. More... | |
QString | dir () const |
Return the root dir containing the files to be served. | |
Public Member Functions inherited from Tufao::AbstractHttpServerRequestHandler | |
AbstractHttpServerRequestHandler (QObject *parent=0) | |
Constructs an AbstractHttpServerRequestHandler object. | |
Static Public Member Functions | |
static void | serveFile (const QString &fileName, HttpServerRequest *request, HttpServerResponse *response) |
Analyze the request and serve the file pointed by filename . | |
static bool | serveFile (const QString &fileName, HttpServerResponse *response, int statusCode) |
This member function doesn't serve any file, just set the response body to the contents in the file pointed by filename . More... | |
static qint64 | bufferSize () |
Return the buffer size used. More... | |
static void | setBufferSize (qint64 size) |
Set the buffer size. | |
You can use this class to serve static files under Tufão.
It provides a robust HTTP file server, supporting conditional and byte-range requests.
The two main approaches are:
The algorithm used to serve files will handle the following set of headers:
It won't handle:
|
explicit |
Constructs a HttpFileServer object.
parent
is passed to the QObject constructor.
dir
is used as root dir to serve files.
|
static |
Return the buffer size used.
When serving files, HttpFileServer allocates some bytes of the file in the memory before sending it to the network. The maximum space allocated is the buffer size. This method returns what number is this.
|
slot |
It searchs for the file requested in the root dir and respond to the request, if the file is found.
|
static |
This member function doesn't serve any file, just set the response body to the contents in the file pointed by filename
.
It's useful in some scenarios, like serving 404-pages.
void Tufao::HttpFileServer::setDir | ( | const QString & | dir | ) |
Set the root dir.
The root dir is the dir containing the files to be served by the HttpFileServer object.