AfterRequest Example | Qt HTTP Server 6.4.1

- Qt 6.4
- Qt HTTP Server
- Qt HTTP Server Examples
- AfterRequest Example
- Qt 6.4.1 Reference Documentation

# AfterRequest Example

     // Copyright (C) 2020 Mikhail Svetkin <mikhail.svetkin@gmail.com>
     // Copyright (C) 2018 The Qt Company Ltd.
     // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

     #include <QtCore>
     #include <QtHttpServer>

     int main(int argc, char *argv[])
     {
         QCoreApplication app(argc, argv);

         QHttpServer httpServer;
         httpServer.route("/", []() {
             return "Hello world";
         });

         httpServer.afterRequest([](QHttpServerResponse &&resp) {
             resp.setHeader("Server", "Super server!");
             return std::move(resp);
         });

         const auto port = httpServer.listen(QHostAddress::Any);
         if (!port) {
             qDebug() << QCoreApplication::translate(
                     "QHttpServerExample", "Server failed to listen on a port.");
             return 0;
         }

         qDebug() << QCoreApplication::translate(
                 "QHttpServerExample", "Running on http://127.0.0.1:%1/ (Press CTRL+C to quit)").arg(port);

         return app.exec();
     }