diff options
author | Tasuku Suzuki <tasuku.suzuki@qbc.io> | 2019-04-27 15:54:53 +0900 |
---|---|---|
committer | Tasuku Suzuki <tasuku.suzuki@qbc.io> | 2019-06-14 15:19:29 +0900 |
commit | fc7908e628072c8d06aa4519add8a10d990ac76d (patch) | |
tree | f5a98151561b4cd7400f7e675338a2885af3fff2 /examples/httpserver | |
parent | c88c462ac7b7fd12a842cd2d77a8f4eef63a9bcd (diff) |
Introduce QHttpServerResponse::fromFile()
This is a shortcut for static file contents.
Change-Id: I54d97c60822e661c1405f27ea8d4598f0363b144
Reviewed-by: Mikhail Svetkin <mikhail.svetkin@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'examples/httpserver')
-rw-r--r-- | examples/httpserver/simple/assets.qrc | 5 | ||||
-rw-r--r-- | examples/httpserver/simple/assets/qt-logo.png | bin | 0 -> 1032 bytes | |||
-rw-r--r-- | examples/httpserver/simple/main.cpp | 4 | ||||
-rw-r--r-- | examples/httpserver/simple/simple.pro | 3 |
4 files changed, 12 insertions, 0 deletions
diff --git a/examples/httpserver/simple/assets.qrc b/examples/httpserver/simple/assets.qrc new file mode 100644 index 0000000..e623543 --- /dev/null +++ b/examples/httpserver/simple/assets.qrc @@ -0,0 +1,5 @@ +<RCC> + <qresource prefix="/"> + <file>assets/qt-logo.png</file> + </qresource> +</RCC> diff --git a/examples/httpserver/simple/assets/qt-logo.png b/examples/httpserver/simple/assets/qt-logo.png Binary files differnew file mode 100644 index 0000000..39a4a26 --- /dev/null +++ b/examples/httpserver/simple/assets/qt-logo.png diff --git a/examples/httpserver/simple/main.cpp b/examples/httpserver/simple/main.cpp index 410d6fe..b76f944 100644 --- a/examples/httpserver/simple/main.cpp +++ b/examples/httpserver/simple/main.cpp @@ -104,6 +104,10 @@ int main(int argc, char *argv[]) }; }); + httpServer.route("/assets/<arg>", [] (const QUrl &url) { + return QHttpServerResponse::fromFile(QStringLiteral(":/assets/%1").arg(url.path())); + }); + const auto port = httpServer.listen(QHostAddress::Any); if (port == -1) { qDebug() << QCoreApplication::translate( diff --git a/examples/httpserver/simple/simple.pro b/examples/httpserver/simple/simple.pro index d1f0889..a4ba393 100644 --- a/examples/httpserver/simple/simple.pro +++ b/examples/httpserver/simple/simple.pro @@ -9,3 +9,6 @@ SOURCES += \ target.path = $$[QT_INSTALL_EXAMPLES]/httpserver/simple INSTALLS += target + +RESOURCES += \ + assets.qrc |