summaryrefslogtreecommitdiffstats
path: root/tests
Commit message (Collapse)AuthorAgeFilesLines
* Introduce QHttpServerFutureResponseMikhail Svetkin2020-06-111-0/+32
| | | | | | | Provide simple API for asynchronous resoponses Change-Id: Ic0c92cce95751dc8f9d6b0dfa96e39019f5f5e9e Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Don't destory socket and request objects while handling a requestMikhail Svetkin2020-06-061-0/+20
| | | | | | Task-number: QTBUG-84617 Change-Id: Ibf98fb329c817ae39f66e539cdb30a4194cb3b42 Reviewed-by: Mikhail Svetkin <mikhail.svetkin@gmail.com>
* Add QHttpServer::afterRequestMikhail Svetkin2020-05-142-18/+53
| | | | | | | | This function allows to register a function to be run after each request. Task-number: QTBUG-77090 Change-Id: I40dd4c1e9a447fbe034149ffc1923c7c814cf0e9 Reviewed-by: Mikhail Svetkin <mikhail.svetkin@gmail.com>
* tst_qhttpserver: Add expected warning messagesMikhail Svetkin2020-05-141-0/+6
| | | | | Change-Id: Iffbde346b6e8454dc9e8b19d96e8a4a4e860f1e2 Reviewed-by: Mikhail Svetkin <mikhail.svetkin@gmail.com>
* Add cmake support for Qt6/dev branchMikhail Svetkin2020-05-0512-8/+95
| | | | | | Change-Id: Icca0edab01d6028d786b76f99fba388565bd6e76 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
* Add cmake test and remove dead codeMikhail Svetkin2020-04-191-0/+1
| | | | | | | cmake test was removed accidentally 9719bf64bb471b8da10e8a5aa419308e8d3b1238 Change-Id: I96f3717e936256d353816094506c6b48538f0fc8 Reviewed-by: Mikhail Svetkin <mikhail.svetkin@gmail.com>
* Add dependencies file for CoinMikhail Svetkin2020-04-192-2/+1
| | | | | | | | Coin by default uses dev branch of qtbase. Add 5.12 qtbase into the dependencies file Change-Id: I849ea65e36c74f153dbd5531c01e3a3b00ab4fef Reviewed-by: Mikhail Svetkin <mikhail.svetkin@gmail.com>
* Do not disconnect on HTTP CONNECT methodMikhail Svetkin2020-02-261-1/+8
| | | | | | | | | | According HTTP/1.1 specifications (RFC 7231) CONNECT is intended only for use in requests to a proxy. That it is why http-parser sets the upgrade flag. This patch will allow users to decide how to handle this. Change-Id: Ic2d10ca4ab113b4cac85e14f15af7890d5773e98 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Fix memory leak in testMikhail Svetkin2020-02-201-5/+5
| | | | | | | | | QTcpSocket was created on heap without a parent and it never called delete. Change-Id: I492633f9797427e546065f9afadf19a672dc552c Reviewed-by: Tasuku Suzuki <tasuku.suzuki@kdab.com> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Make QAbstractHttpServer::listen return 0 on failMårten Nordheim2020-02-182-3/+6
| | | | | | | | | | | | | | | | Which then makes it compatible with other listen() functions in Qt in the sense that doing if (server.listen()) will behave consistently. Ports being listened to can then be gotten from the new serverPorts() function, mirroring serverPort() from QTcpServer etc., except it's a QVector. This is a source incompatible change, but is allowed because this module is still in tech preview. Fixes: QTBUG-79411 Change-Id: I09764afbf8fd866af4f43ab90fcf9c2e9a373237 Reviewed-by: Mikhail Svetkin <mikhail.svetkin@gmail.com>
* Fix crash when CONNECT method is usedTasuku Suzuki2020-02-131-0/+19
| | | | | | | | | | When the parser received "CONNECT / HTTP/1.1\n\n", its upgrade variable is set to 1 even though there is no "upgrade" header available. In this case, QMap::find() returns its end. Task-number: QTBUG-82053 Change-Id: I41cc23511459c6735a474bb7b903638dd4b1208f Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Refactor access to QMetaEnum for QHttpServerRequest::MethodMikhail Svetkin2019-11-101-6/+2
| | | | | | | | Replace QHttpServerRequest::staticMetaObject.indexOfEnumerator("Method") with QMetaEnum::fromType<QHttpServerRequest::Method>. Change-Id: Idda142fd065e9ce216e2d76c09a5b19d384df1b3 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Allow using QHttpServerRequest/Responder at the same timeMikhail Svetkin2019-10-252-6/+33
| | | | | | Fixes: QTBUG-77088 Change-Id: I2208cee290d086339aba705f959c57e0f6a73a87 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QHttpServerRouterViewTraits: Make it simpler and testableMikhail Svetkin2019-10-241-0/+326
| | | | | | | | | | | | | Currently QHttpServerRouterViewTraits contains all helpers and tools inside itself. It is hard to read and extend. This patch: - Moves all helper and tools to QtPrivate namespace - Tries to "simplify" template magic - Adds support for unit test Change-Id: I6aa443b286c4c896b8dbfee85fffb638328868ad Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* HTTPS supportSylvain Garcia2019-10-042-50/+213
| | | | | | | | | | | | | | | Added new `QAbstractHttpServer::sslSetup` which enables HTTPS usage. Added new `QSslServer` which inherits from `QTcpServer` and configures incoming TCP clients to use SSL. [ChangeLog][QHttpServer][Https support] Https support added to QAbstractHttpServer class Change-Id: I536cf48b86b246e3f4b9d960f793b93670afe06f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Guy Poizat <gerrit.qt@gmail.com> Reviewed-by: Mikhail Svetkin <mikhail.svetkin@gmail.com>
* QHttpServerResponse: Extend the APIMikhail Svetkin2019-10-032-0/+94
| | | | | | | | | | | | Add new API for HTTP headers manipulations. Add QHttpServerResponse::write function which will allow to write custom response objects in a future. Fixes: QTBUG-76933 Change-Id: I744303be1b517c07f698c4a3dd2c4296f77e3b03 Reviewed-by: Tasuku Suzuki <tasuku.suzuki@tqcs.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QHttpServerResponse: Change text/html -> application/x-emptyMikhail Svetkin2019-08-221-5/+5
| | | | | | | | | | It does not make sense to set "text/html" as content type for empty responses. Change-Id: I93f540c97cef38409f1479f1c332349155edd176 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Tasuku Suzuki <tasuku.suzuki@qbc.io>
* Add QHttpServerLiteralsMikhail Svetkin2019-08-215-16/+31
| | | | | | | | | | Currently we have a lot of duplication of most common HTTP headers and their values. This patch moves them to one place. Change-Id: Idf9ddc5164e81649b4cc37ed92a516eb1eedab3a Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Tasuku Suzuki <tasuku.suzuki@qbc.io>
* QHttpServerResponder: refactor and extend the APIMikhail Svetkin2019-08-202-4/+102
| | | | | | | | | | | | | Currently QHttpServerResponder is not flexible enough: - Does not allow to rewrite headers - Does not allow to write headers without storing them internaly first - Does not provide API to make your own HTTP response This patch will help to implement QHttpServerResponse setHeaders/addHeaders Change-Id: If9e21f7f7a58629bfedad0f10cab67d67fce0a89 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QHttpServerResponse: add ctor for QJsonArrayMikhail Svetkin2019-07-111-0/+16
| | | | | | | Task-number: QTBUG-76619 Change-Id: Ibce12e33754e950f467c8fb291d447cfc0694062 Reviewed-by: Tasuku Suzuki <tasuku.suzuki@qbc.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QHttpServerResponse: use compact mode for json objectsMikhail Svetkin2019-07-111-0/+15
| | | | | | Change-Id: Ia01f2f9a1483b326bc92eda20045f9764616cf66 Reviewed-by: Tasuku Suzuki <tasuku.suzuki@qbc.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* QAbstractHttpServer: Simplify handleNewConection/handleReadyReadMikhail Svetkin2019-07-091-4/+18
| | | | | | | | Remove usage of QObjectUserData. Remove usage of QHash of QHttpServerRequest. Change-Id: I8a6c44bcfefc12c841ae67562e9bbec10f6ab9bf Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Introduce QHttpServerResponse::fromFile()Tasuku Suzuki2019-06-146-1/+66
| | | | | | | | 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>
* Fix crash for passing lambda with captures to QHttpServer::routeMikhail Svetkin2019-05-151-8/+36
| | | | | | | | | | | | QHttpServer::route accepted the lambda by universal reference, but did not pass it to QHttpServerRouter::addRule by std::forward. We can not initialize lambda captures with C++11. So we always need to copy the lambda by value. Task-number: QTBUG-74882 Change-Id: I3e2dc6003624414d0ff45ba2e2f1af472e219ff1 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Use Qt5TestMacros for run cmake testsMikhail Svetkin2019-05-151-11/+1
| | | | | Change-Id: I54486c20d047b5aa73e6012d43c9ca5019f9a51f Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Remove unused signalMikhail Svetkin2019-05-091-2/+0
| | | | | | Change-Id: I28fb6f9f45e43d21cace1978c03acd330a9e6faa Reviewed-by: Tasuku Suzuki <tasuku.suzuki@qbc.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Fix tests failure introduced by the mime type detectionTasuku Suzuki2019-05-092-25/+25
| | | | | | | | | | Commit 4f64330b39bd528a84241e976baa464c6dc89de1 changes some mime types of responses to text/plain. The commit also FIXED the "No newline at end of file" warning in a test data for QHttpServerResponder. Change-Id: I9b6b1878a2b61bf80db1e39b81ae75c4cedce615 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Add a fork() testJesus Fernandez2019-04-291-0/+58
| | | | | | Change-Id: Ic7c797f9757ad14803154f6125298bfc8fe03baa Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Find proper mime type for QByteArray dataTasuku Suzuki2019-04-2611-4/+174
| | | | | | | | | | QByteArray can be used for any data that QMimeDatabase understands Change-Id: I17d8f0060065c0a93fc4a8cf6450bdd11aed49d0 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Mikhail Svetkin <mikhail.svetkin@qt.io> Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
* Fix support for keep-alive connectionMikhail Svetkin2019-04-081-3/+59
| | | | | | | | | | QAbstractHttpServer did not clear a request's internal properties (headers, url, body). If a request has a keep-alive header, QAbstractHttpServer should clear the request's internal properties. Change-Id: I2dfd0565369bd3291cd8d9900045c5a7f9d43ca3 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Accept a string as request method in QHttpServer::route()Mikhail Svetkin2019-04-042-1/+94
| | | | | | | | | | | | | | | Allow writing simpler source code. For example: httpserver.route("/", "GET|POST", [] () { return ""; }) Instead of: httpserver.route("/", QHttpServerRequest::Method::Post | QHttpServerRequest::Method::Get, [] () { return ""; }) Change-Id: Id0a754eccaba6b5f9f3be6a3b975383eb94840a0 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Fix HTTP chunked request body handlingMikhail Svetkin2019-04-031-2/+43
| | | | | | Task: QTBUG-74843 Change-Id: I4978c80195246c99a5e6d1e608b3980f56b39207 Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
* Allow use of custom data structures as router callback argumentsMikhail Svetkin2019-03-061-0/+46
| | | | | | | | Change-Id: I6dcc66a95b72bb461f237cade0352a0177065227 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Fix build on WindowsMaurice Kalinowski2019-02-281-0/+1
| | | | | | Change-Id: I7bb287dedfc146ba717a69170cec529d7ef7fadb Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Fix several build issues and fix the unit testsJesus Fernandez2019-02-286-23/+28
| | | | | | | | | | It is required to have continuous integration enabled in the repository. Change-Id: I71728a6e89841640e77c50a05cf59f34d697f897 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Use QStringLiteralJesus Fernandez2019-02-121-1/+2
| | | | | | | | | To avoid using the deprecated QString implicit constructor Change-Id: If6f29952b0dbec96437e0b940c3cb52a801c0d32 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
* Fix license headersJesus Fernandez2019-01-314-64/+24
| | | | | | Change-Id: Ie15244adb917e2938fe7897c30d4616218d26ac0 Reviewed-by: Mikhail Svetkin <mikhail.svetkin@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Introduce QHttpServerMikhail Svetkin2019-01-253-0/+354
| | | | | | | | | QHttpServer provides a simplified interface to QAbstractHttpServer and QHttpServerRouter. Change-Id: I884204aa8140bbab4c0d6a8ab4c798e0b2470e29 Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Introduce QHttpServerRouterMikhail Svetkin2019-01-233-1/+232
| | | | | | | | | Provide simple API for routing, parsing, capture and call callback Change-Id: Ibd7c37282d00bd56f96d841db92b473a65a2bf5c Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
* Fix tst_QAbstractHttpServer::requestMikhail Svetkin2018-12-201-2/+2
| | | | | | | | | | We have undefined behavior when we check server.method. Because HttpServer::method was uninitialized. Also start checking a return value from QTcpServer::listen. Change-Id: Ib7c31f33be956582a6ef264743ca9e44d4de24b1 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Fix build the test without the websocket supportMikhail Svetkin2018-12-201-1/+2
| | | | | Change-Id: If32f6a7a42258f9a5a8bed15c776ffa18240da24 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Fix CMake testsJesus Fernandez2018-10-223-4/+67
| | | | | | Change-Id: I5a79cfc3bab647f9bec29e8b08f9262b211c83b1 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
* Refactor QAbstractHttpServer::servers()Tasuku Suzuki2018-10-221-0/+18
| | | | | Change-Id: I11e7100dd5f25d6c02bef28f4c53ce3acc257390 Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
* Refactor QHttpServerResponder::write(QIODevice, ...)Mikhail Svetkin2018-10-043-0/+56
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The current implementation has several problems. 1. The function takes an ownership the QIODevice and puts it into a smartpointer. Also we conntected socket's destroyed signal to lambda which has captured the smartpointer. So if responder does not find the file, the smartpointer will call deleteLater which then will call socket::destroyed and then lambda will be called and try to access the smartpointer which does not exist anymore. 2. The function takes an ownership the file(QIODevice) and puts it into a smartpointer. Also we conntected the QTemporaryFile's aboutToClose signal to lambda which has captured the smartpointer. So when the QTemporaryFile calls destructor it will emit aboutToClose signal which will call the lambda and this lambda will try to access the smartpointer which does not exist anymore. 3. If we send a file smaller than chunksize, IOChunkedTransfer we will never be deleted. 4. Does not check a socket connection type (keep-alive). 5. Does not send anything if file is not found or opened in wrong mode. Change-Id: I699e7d5a462c4b8d195908747bf0386132b19973 Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
* Introduce QHttpServerResponderJesus Fernandez2018-09-263-2/+166
| | | | | | | | | | It encapsulates the socket and gives an API to answer the received requests. Change-Id: Ic95db2c50224a650a02b206faca9a0ff8d1cc62b Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Ryan Chu <ryan.chu@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
* Reduce project dependenciesJesus Fernandez2018-07-231-1/+1
| | | | | Change-Id: Ic693da5fb70e3352a06ca4f42643ee3b1f7c2625 Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
* Allow build tst_qabstracthttpserver without qtConfig(private_tests)Mikhail Svetkin2018-07-201-1/+0
| | | | | | Change-Id: I6d0c6e9f4bbdf203fb29ae611e064aa284d52ebe Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
* Remove unused QNetworkReplyMikhail Svetkin2018-07-201-2/+1
| | | | | | Change-Id: I536226270db1534b0bda1a2205898c291285721a Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
* Fix inccorect parsing url with spacesMikhail Svetkin2018-07-181-0/+2
| | | | | Change-Id: I942bd80cf3cefaa9f0194ce3281640a3b5077ed2 Reviewed-by: Jesus Fernandez <Jesus.Fernandez@qt.io>
* Introduce Qt HttpServer frameworkJesus Fernandez2018-07-166-0/+197
Small, Qt integrated framework for creating specialized http server. Goals of the project: - Create a framework allowing creation of a specialized web server running in non public networks (home and company networks, stealth or hidden services) - Create an easy tool for developers to embed http servers in their apps. - Playground to narrow down problems in Qt, related to network stack, but also to explore general usability. - Potentially reduce code duplication in Qt. Not goals: - Standalone server, in particular not Apache or nginx replacement Change-Id: I0d8b83e50992b9a95c88f4735539329279cf5425 Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>