Qt HTTP Server 6.4.1

- Qt 6.4
- Qt HTTP Server
- Qt 6.4.1 Reference Documentation

# Qt HTTP Server

Qt HTTP Server supports building HTTP server functionality 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.

This module is in Technical Preview state.

## Overview

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

An HTTP server can be 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.

Runtime 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().

## Using the Module

Using a Qt module requires linking against the module library, either directly or through other dependencies. Several build tools have dedicated support for this, including CMake and qmake.

### Building with CMake

Use the `find_package()` command to locate the needed module components in the Qt6 package:

     find_package(Qt6 REQUIRED COMPONENTS HttpServer)
     target_link_libraries(mytarget PRIVATE Qt6::HttpServer)

See also the Build with CMake overview.

### Building with qmake

To configure the module for building with qmake, add the module as a value of the QT variable in the project's .pro file:

     QT += httpserver

## Licenses

Qt HTTP Server is available under commercial licenses from The Qt Company. In addition, it is available under the GNU General Public License, version 3. See Qt Licensing for further details.

## Reference

- Qt HTTP Server Logging
- C++ Classes

## Examples

The module provides the following Examples as a guide to using the API.