QHttpEngine
1.0.0
Simple and secure HTTP server for Qt applications
|
QHttpEngine provides a simple set of classes for developing HTTP server applications in Qt.
The design goals of QHttpEngine include:
All of QHttpEngine's functionality is included in a single monolithic library.
QHttpEngine has been tested on the following combinations of compiler and operating system:
QHttpEngine is designed in a portable way, so it may run on other compilers and operating systems than the ones listed above. However, the list represents the combinations that are actively tested and officially supported.
QHttpEngine uses CMake for building the library. The library recognizes three options during configuration, all of which are disabled by default (the library is built as a shared library):
BUILD_DOC
- (requires Doxygen) generates documentation from the comments in the source codeBUILD_EXAMPLES
- builds the sample applications that demonstrate how to use QHttpEngineBUILD_TESTS
- build the test suiteIt is also possible to override installation directories by customizing the BIN_INSTALL_DIR
, LIB_INSTALL_DIR
, INCLUDE_INSTALL_DIR
, DOC_INSTALL_DIR
, and EXAMPLES_INSTALL_DIR
variables.
QHttpEngine includes all of the classes you will need to build your HTTP server application.
In order to create an HTTP socket, create an instance of Socket and pass a QTcpSocket* in the constructor:
Once the headersParsed() signal is emitted (and isHeadersParsed() returns true), information about the request can easily be retrieved:
Because Socket derives from QIODevice, writing a response to the client is very simple:
Writing a local file to the socket can be done with little effort by using the QIODeviceCopier class:
To create an HTTP server, simply create an instance of the Server class:
In order to route requests based on their path, a handler must be used. Handlers derive from the Handler class. The simplest of these is the FilesystemHandler class:
A request to /path
will cause the server to respond with the contents of /var/www/path
.
Although it is possible to create a handler that manually routes requests, it is far easier to use the QObjectHandler class and register slots for each path - you can even use the new connection syntax:
A request to /something
will cause the doSomething()
slot to be invoked.