summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorIevgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>2023-02-07 15:30:10 +0100
committerIevgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>2023-02-08 13:49:08 +0100
commit4e409a3bd627a262ada74394511b03e3b583f998 (patch)
tree8a997917522a90e6410667181fec02b5350e6369 /examples
parenta566e5971e2b5852d5d9d7ed1244d4904e5edbc1 (diff)
examples: Integrate 'afterrequest' example into 'simple' example
Task-number: QTBUG-110895 Pick-to: 6.5 Change-Id: Ia44cdb14f2a6e16ca2b5a135b8252384f5465bea Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'examples')
-rw-r--r--examples/httpserver/CMakeLists.txt1
-rw-r--r--examples/httpserver/afterrequest/CMakeLists.txt36
-rw-r--r--examples/httpserver/afterrequest/afterrequest.pro14
-rw-r--r--examples/httpserver/afterrequest/main.cpp33
-rw-r--r--examples/httpserver/httpserver.pro1
-rw-r--r--examples/httpserver/simple/main.cpp7
6 files changed, 7 insertions, 85 deletions
diff --git a/examples/httpserver/CMakeLists.txt b/examples/httpserver/CMakeLists.txt
index b6ce650..70a4098 100644
--- a/examples/httpserver/CMakeLists.txt
+++ b/examples/httpserver/CMakeLists.txt
@@ -1,5 +1,4 @@
if(TARGET Qt::Gui AND TARGET Qt::Concurrent)
qt_internal_add_example(colorpalette)
endif()
-qt_internal_add_example(afterrequest)
qt_internal_add_example(simple)
diff --git a/examples/httpserver/afterrequest/CMakeLists.txt b/examples/httpserver/afterrequest/CMakeLists.txt
deleted file mode 100644
index e9e73c8..0000000
--- a/examples/httpserver/afterrequest/CMakeLists.txt
+++ /dev/null
@@ -1,36 +0,0 @@
-# Copyright (C) 2022 The Qt Company Ltd.
-# SPDX-License-Identifier: BSD-3-Clause
-
-cmake_minimum_required(VERSION 3.16)
-project(afterrequest LANGUAGES CXX)
-
-if(NOT DEFINED INSTALL_EXAMPLESDIR)
- set(INSTALL_EXAMPLESDIR "examples")
-endif()
-
-set(INSTALL_EXAMPLEDIR "${INSTALL_EXAMPLESDIR}/httpserver/${PROJECT_NAME}")
-
-find_package(Qt6 REQUIRED COMPONENTS HttpServer)
-if(ANDROID)
- find_package(Qt6 REQUIRED COMPONENTS Gui)
-endif()
-
-qt_add_executable(afterrequest
- main.cpp
-)
-
-target_link_libraries(afterrequest PRIVATE
- Qt6::HttpServer
-)
-
-if(ANDROID)
- target_link_libraries(afterrequest PRIVATE
- Qt::Gui
- )
-endif()
-
-install(TARGETS afterrequest
- RUNTIME DESTINATION "${INSTALL_EXAMPLEDIR}"
- BUNDLE DESTINATION "${INSTALL_EXAMPLEDIR}"
- LIBRARY DESTINATION "${INSTALL_EXAMPLEDIR}"
-)
diff --git a/examples/httpserver/afterrequest/afterrequest.pro b/examples/httpserver/afterrequest/afterrequest.pro
deleted file mode 100644
index ac06d08..0000000
--- a/examples/httpserver/afterrequest/afterrequest.pro
+++ /dev/null
@@ -1,14 +0,0 @@
-requires(qtHaveModule(httpserver))
-
-TEMPLATE = app
-
-QT = httpserver
-android: QT += gui
-
-SOURCES += \
- main.cpp
-
-target.path = $$[QT_INSTALL_EXAMPLES]/httpserver/afterrequest
-INSTALLS += target
-
-CONFIG += cmdline
diff --git a/examples/httpserver/afterrequest/main.cpp b/examples/httpserver/afterrequest/main.cpp
deleted file mode 100644
index 36aea21..0000000
--- a/examples/httpserver/afterrequest/main.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-// 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();
-}
diff --git a/examples/httpserver/httpserver.pro b/examples/httpserver/httpserver.pro
index 82f9210..311f380 100644
--- a/examples/httpserver/httpserver.pro
+++ b/examples/httpserver/httpserver.pro
@@ -1,7 +1,6 @@
TEMPLATE = subdirs
SUBDIRS = \
- afterrequest \
simple
qtHaveModule(gui): qtHaveModule(concurrent) {
diff --git a/examples/httpserver/simple/main.cpp b/examples/httpserver/simple/main.cpp
index 70183bc..e88bb3d 100644
--- a/examples/httpserver/simple/main.cpp
+++ b/examples/httpserver/simple/main.cpp
@@ -87,6 +87,13 @@ int main(int argc, char *argv[])
return response;
});
+ //! [Using afterRequest()]
+ httpServer.afterRequest([](QHttpServerResponse &&resp) {
+ resp.setHeader("Server", "Qt HTTP Server");
+ return std::move(resp);
+ });
+ //! [Using afterRequest()]
+
const auto port = httpServer.listen(QHostAddress::Any);
if (!port) {
qDebug() << QCoreApplication::translate("QHttpServerExample",