tufao
1.3.0
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) override |
It searchs for the file requested in the root dir and respond to the request, if the file is found. 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. | |
bool | canHandleRequest (const HttpServerRequest &request) |
Returns true iff HttpFileServer::handleRequest will return true. More... | |
Public Member Functions inherited from Tufao::AbstractHttpServerRequestHandler | |
operator std::function< bool (HttpServerRequest &, HttpServerResponse &)>() | |
Implicit conversion operator to std::function functor object. More... | |
virtual bool | handleRequest (Tufao::HttpServerRequest &request, Tufao::HttpServerResponse &response)=0 |
Handles the request using the response object. More... | |
Static Public Member Functions | |
static void | serveFile (const QString &fileName, HttpServerRequest &request, HttpServerResponse &response) |
Analyze the request and serve the file pointed by filename . More... | |
static bool | serveFile (const QString &fileName, HttpServerResponse &response, HttpResponseStatus 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. | |
static bool | canHandleRequest (const HttpServerRequest &request, const QString &root) |
Returns true iff HttpFileServer::handleRequest will return true. More... | |
static std::function< bool(HttpServerRequest &, HttpServerResponse &)> | handler (const QString &rootDir) |
Returns a handler that don't depends on another object. More... | |
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.
bool Tufao::HttpFileServer::canHandleRequest | ( | const HttpServerRequest & | request | ) |
Returns true iff HttpFileServer::handleRequest will return true.
|
static |
Returns true iff HttpFileServer::handleRequest will return true.
|
static |
Returns a handler that don't depends on another object.
The purpose of this alternative handler is to free you of the worry of maintain the HttpFileServer's object (lifetime) while the functor object is being used.
rootDir | The root dir to serve files. |
|
overrideslot |
It searchs for the file requested in the root dir and respond to the request, if the file is found.
|
static |
Analyze the request
and serve the file pointed by filename
.
|
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.