tufao  0.8.1
An asynchronous web framework for C++ built on top of Qt
 All Classes Namespaces Functions Variables Enumerations Enumerator Pages
Tufao::HttpFileServer Class Reference

You can use this class to serve static files under Tufão. More...

+ Inheritance diagram for Tufao::HttpFileServer:
+ Collaboration diagram for Tufao::HttpFileServer:

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.
 

Detailed Description

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:

  • If-Modified-Since
  • If-Unmodified-Since
  • If-Range
  • Range

It won't handle:

  • ETag (If-Match and If-None-Match headers)
  • Cache-Control response header: Useful for set cache max age
  • Content-Disposition response header
  • Content-MD5 response header
  • Content-Type response header. This header is used to inform the mime type of the file to the client.
Since
0.3

Constructor & Destructor Documentation

Tufao::HttpFileServer::HttpFileServer ( const QString &  dir,
QObject *  parent = 0 
)
explicit

Constructs a HttpFileServer object.

parent is passed to the QObject constructor.

dir is used as root dir to serve files.

Member Function Documentation

static qint64 Tufao::HttpFileServer::bufferSize ( )
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.

Note
The buffer size is global to all HttpFileServer objects.
See Also
setBufferSize
bool Tufao::HttpFileServer::handleRequest ( Tufao::HttpServerRequest request,
Tufao::HttpServerResponse response,
const QStringList &  = QStringList() 
)
slot

It searchs for the file requested in the root dir and respond to the request, if the file is found.

Note
This method won't let requests access files outside the root dir folder and should be prefered over self-made implementations, as its safer.
static bool Tufao::HttpFileServer::serveFile ( const QString &  fileName,
HttpServerResponse response,
int  statusCode 
)
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.


The documentation for this class was generated from the following file: