Qt HTTP Server Overview

Qt HTTP Server supports building an HTTP server into an application. It provides an implementation of the server side of the HTTP protocol, and also provides security through Transport Layer Security. Because it is designed for embedding in applications to expose things in a trusted network, and doesn't have robustness/security as a goal, it is not suitable for being internet-facing.

How does it work?

Qt HTTP Server provides building blocks for embedding a lightweight HTTP server in an application. There are classes for the messages sent and received, and for the different parts of an HTTP server.

How do you use it?

An HTTP server can created by subclassing the QAbstractHttpServer class, and overriding the handleRequest() function. The QAbstractHttpServer class provides functions for listening to incoming ports or binding to an existing QTcpServer. Dispatching to callables based on incoming URLs can be simplified by using the QHttpServerRouter class.

This can be simplified even further by using the QHttpServer class. The QHttpServer class is a subclass of QAbstractHttpServer, and defines an overloaded route function to bind callables to different incoming URLs, and an afterRequest function to process the response further.

The logging can be configured as described here.

When security is needed and you have Qt compiled with support for TLS, you can bind QAbstractHttpServer and its subclasses to a QSslServer object, providing Transport Layer Security handling, turning it into an HTTPS server. This can also be achieved by calling the QAbstractHttpServer::sslSetup() function before calling listen().