Commit Graph

90 Commits

Author SHA1 Message Date
Øystein Heskestad 334a92f459 Add test that routes can send back data in multiple parts asynchronously
Add test to ensure that a route can be added that will be executed
asynchronously and can send back data to the client in multiple parts.

Task-number: QTBUG-108127
Change-Id: I3262da98559ff1a458e0305dff729da8538ecae5
Reviewed-by: Matthias Rauter <matthias.rauter@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2025-08-08 19:13:27 +02:00
Øystein Heskestad 7eda15d031 Allow routes to return QFuture<void> and write using responder
Add support for route handlers that return QFuture<void> and
respond using QHttpServerResponder&& argument in another thread.

For an HTTP/2 connection multiple requests can be responded to at
the same time, but for an HTTP/1.x connection the requests are
handled one at a time in the order they appear. For CPU intensive
requests the HTTP/1.x connections can still benefit from the
QHttpServer thread being relieved of the work.

The socket I/O is always handled in the thread that QHttpServer
belongs to.

Now that QHttpServerRequest is copyable make it possible to pass it
by value to the route handlers.

Add tests including invalid route() calls that are conditionally
enabled, and will static_assert when enabled.

Renamed Valid to Value and removed old Value, and as a
consequence removed usages of Valid from tests.

[ChangeLog] Added support for routes handlers that return
QFuture<void> and respond using QHttpServerResponder&& argument
in another thread.

Task-number: QTBUG-108127
Change-Id: I58e3c07f5eb54b3f9443e569151b82827ef8f5f8
Reviewed-by: Matthias Rauter <matthias.rauter@qt.io>
2025-08-06 10:01:00 +02:00
Øystein Heskestad 114daf0d13 Make sure reading from a QIODevice is done before handling next request
HTTP/1.x can only handle responding to a single request at a time on
the same socket. Do not proceed to the next incoming request until
reading from a QIODevice is done to prevent out of order writes.

Failing test now succeeds.

Task-number: QTBUG-138611
Pick-to: 6.10 6.9 6.8
Change-Id: Ia0eb96b57080c8373960932fac217315f621cbfe
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2025-07-23 11:49:25 +02:00
Øystein Heskestad 0563f1c42e Test that reading from multiple QIDevices on an HTTP/1 connection fails
Because HTTP/1.x connections can only respond to a single request at a
time, and the QHttpServer proceeds to the next incoming connection as
soon as it has started writing from a QIODevice, the response data is
received out of order.

Task-number: QTBUG-138611
Pick-to: 6.10 6.9 6.8
Change-Id: I9979f8414efc62c5561efa6152359ac807008f40
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2025-07-23 11:49:19 +02:00
Øystein Heskestad 46ee9ede50 Make tests compile without the concurrency feature enabled
Add missing include guards and skip tests that need the concurrency
feature.

Pick-to: 6.10 6.9 6.8
Change-Id: I8e8c0ef91b8359bf9fb6416f19f70f6c02dc88a9
Reviewed-by: Matthias Rauter <matthias.rauter@qt.io>
2025-07-10 10:34:37 +02:00
Øystein Heskestad ea669306b2 Fix writing from sequential QIODevices to HTTP(S)/1.(0/1) clients
When handling HTTP(S)/1.1 clients use chunked transfer encoding
for sequential QIODevices, because sequential QIODevices don't
know their length. The failure to do so caused clients to hang.
When handling HTTP(S)/1.0 clients disconnect after write because
such clients don't support chunked transfer encoding.

Removed expect_fail from tests that now work.

Fixes: QTBUG-137330
Pick-to: 6.10 6.9 6.8
Change-Id: Ie7a0e106c5475b8298697cdee0ba080acab3ce97
Reviewed-by: Lena Biliaieva <lena.biliaieva@qt.io>
Reviewed-by: Matthias Rauter <matthias.rauter@qt.io>
2025-07-09 14:21:13 +02:00
Øystein Heskestad bdd1b7f977 Sequential QIODevice in tst_qhttpserver now emits readChannelFinished
The mock QIODevice SequentialIODevice in test now emits
readChannelFinished() when all data is available.

Now it also adds data multiple times with a delay instead
of having it available from the time of construction.

A new test is added to ensure that large amounts of data
can be read.

Task-number: QTBUG-137330
Pick-to: 6.10 6.9 6.8
Change-Id: Ibea47feefeffebd64a43a1a1ec5f00687b246ea6
Reviewed-by: Matthias Rauter <matthias.rauter@qt.io>
2025-07-04 16:33:01 +02:00
Matthias Rauter 071115caaa Remove unused test data
Pick-to: 6.10 6.9 6.8 6.5
Change-Id: I371d8948e7b1bbd6760c52dee4e8a3a1e84d2102
Reviewed-by: Øystein Heskestad <oystein.heskestad@qt.io>
2025-07-01 15:54:16 +02:00
Øystein Heskestad 5603b70b93 Test that writing from an empty sequential QIODevices hangs client
Reading from an empty sequential QIODevice when writing to an
HTTP/1.1 or HTTPS/1.1 client hangs the client. Add tests that
are expected to fail.

Task-number: QTBUG-137330
Pick-to: 6.10 6.9 6.8
Change-Id: I90e5826c05119fe950166b3da06df1aac093ab01
Reviewed-by: Matthias Rauter <matthias.rauter@qt.io>
2025-06-17 10:29:37 +02:00
Øystein Heskestad 355622a849 Reset configuration after executing tst_QHttpServer::keepAliveTimeout()
To prevent test from affecting subsequent tests set keep-alive timeout
back to default settings after performing test.

Task-number: QTBUG-75087
Change-Id: I0f1d5cb1cb6fca727571d7781bb85fa0612dfd06
Reviewed-by: Matthias Rauter <matthias.rauter@qt.io>
2025-06-10 13:36:50 +02:00
Øystein Heskestad 33ed6d70c8 Test that writing from a sequential QIODevice to HTTP/1.1 hangs client
Reading from a sequential QIODevice when writing to a HTTP/1.1 or
HTTPS/1.1 client hangs the client. Add tests that are expected to
fail.

Task-number: QTBUG-137330
Pick-to: 6.10 6.9 6.8
Change-Id: I2607c3d18da18ca1ecd94936dfbe219f5fc98b7d
Reviewed-by: Matthias Rauter <matthias.rauter@qt.io>
2025-06-10 12:13:54 +02:00
Lena Biliaieva c408098014 Add keep-alive timeout for QHttpServer
[ChangeLog][QHttpServerConfiguration] Add methods to configure
keep-alive timeout for QHttpServer.

[ChangeLog][QAbstractHttpServer] Add keep-alive timeout for
HTTP/1 and HTTP/2 connections.

Task-number: QTBUG-75087
Change-Id: Ic54a4102b52cb24004bb5c1f2c4fa6e3a98fc01d
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2025-05-21 12:41:46 +02:00
Øystein Heskestad fdc52d19a8 Split QHttpServerRequestPrivate into itself and QHttpServerParser 4/4
Make QHttpServerRequest copyable and update the traits templates to
handle this. Make QHttpServer::sendResponse() for futures copy the
QHtppServerRequest instead of passing it by reference and update
test that was expected to fail. Add QHttpServerRequest::create()
to create QHttpServerRequest from QHttpServerParser.

[ChangeLog][QtHttpServerRequest] Made QHttpServerRequest copyable

Task-number: QTBUG-133519
Change-Id: I3af08b4e2a579691fbf3b3150fcf553a5615ac62
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2025-04-03 17:53:37 +02:00
Matthias Rauter 1e43423383 Remove implicit capture of this with [=]
Implicit capture of this via [=] is deprecated in C++20.

This patch avoids the compiler warning
tst_qhttpserver.cpp:488:34: warning: implicit capture of ‘this’
via ‘[=]’ is deprecated in C++20 [-Wdeprecated]
  488 |         return QtConcurrent::run([=]() {

Amends: 7c6ff5fab9

Pick-to: 6.9 6.8
Change-Id: Id8467dc58fbabe1f36dec894ee101ef5853b4c73
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Øystein Heskestad <oystein.heskestad@qt.io>
2025-04-02 09:02:49 +02:00
Øystein Heskestad 7c6ff5fab9 Add failing test that show that QHttpServerRequest is overwritten
Each QHttpServerHttp[12]ProtocolHandler has a single
QHttpServerRequest object, causing issues with concurrent route
handlers as the protocol handlers overwrite the same request.

Add a test to demonstrate that the QHttpServerRequest object changes
between the start of route handlers and the execution of
afterRequestHandlers when a long-running handler returns
QFuture<QHttpServerResponse>.

Task-number: QTBUG-133519
Pick-to: 6.9 6.8
Change-Id: I2293c4790db9d04ea15246da3df244b1ed35b026
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2025-03-18 16:03:56 +01:00
Timur Pocheptsov bba15a7cf5 QHttpServer auto-tests: use a function provided by QTest
Instead of having code-duplicates.

Pick-to: 6.9 6.8
Task-number: QTBUG-132645
Change-Id: I6976ae44a0ab14857d71d1cd6eef3cc09e40db34
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2025-02-18 16:51:37 +01:00
Timur Pocheptsov fbfc0ab8d8 tst_qhttpserver: do not block the test with keychain access dialog
Our approach with a temporary keychain stopped working on macOS 15,
where we fortunately have a new option when importing a PKCS12 blob.
But it is possible to build using SDK 14 and then run on macOS 15,
where our trick would fail. In this case, skip the test/SSL usage.

Task-number: QTBUG-130500
Pick-to: 6.8
Change-Id: Iebe31d2d6affa686ccb4287cd80c2c5683cc787a
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2024-10-26 07:50:23 +02:00
Tor Arne Vestbø 4482206a08 Blacklist tst_QHttpServer::pipelinedRequests on macOS 15
Task-number: QTBUG-130500
Change-Id: I457922a59fd90a05d2bbfab31dc6a913f03e6fa1
Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io>
2024-10-24 09:48:36 +02:00
Matthias Rauter 945a3c209c Use context object in QHttpServer::route
Use a context object and QtPrivate:makeCallableObject instead
of std::function when adding routes.

The rvalue was exchanged with a reference in the callback signature
because QMetaObject::invokeMethod is not prepared to handle rvalues.

The context object is used for two purposes, to ensure that a
rule does not outlive the context object, and also it is posssible
to use it as an object to call a member function on.

Pick-to: 6.8
Change-Id: Ibc5478f2dab77f4aa4891819b1c7743c9767849e
Reviewed-by: Øystein Heskestad <oystein.heskestad@qt.io>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2024-09-03 18:21:17 +02:00
Øystein Heskestad 78cd7d0817 Rename test with duplicate data tag
The QHttpServer tests has two tests with the data tag "arg:string".
Rename one of them.

Pick-to: 6.8
Change-Id: I26565be5dff17f95300fed9b6bc9db19b5df3618
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2024-09-03 10:11:32 +00:00
Matthias Rauter 6acb3ccf22 Set afterRequest callback with a context object and remove rvalue
Use QtPrivate::makeCallableObject() and a context object instead
of std::function() when calling afterRequest(). It's signature is
now constrained to take both request and response in that particular
order.

The rvalue was exchanged with a reference in the callback signature
because QMetaObject::invokeMethod is not prepared to handle rvalues.

The function is renamed to addAfterRequestHander() to clarify
its function.

Pick-to: 6.8
Task-Id: QTBUG-128113
Change-Id: If3af3b811f54fe4be2b14d5c768b3a61b4f32bb6
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2024-09-02 08:05:04 +02:00
Matthias Rauter 76e55a052f Set missinghandler callback with a context object and remove rvalue
Use QtPrivate::makeCallableObject() and a context object instead
of std::function() when calling setMissingHandler(). Also added
clearMissingHandler() to set the handler back to the default behavior.

The rvalue was exchanged with a reference in the callback signature
because QMetaObject::invokeMethod is not prepared to handle rvalues.

Pick-to: 6.8
Task-Id: QTBUG-128113
Change-Id: If02c67a0ee200b458d9f8051a23a9307fce6e59a
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2024-08-30 17:57:37 +02:00
Matthias Rauter 962d95298f Simplify and constrain route API
The route convenience method of QHttpServer was a purely variadic
template function. However, it expected a strict syntax of (QString,
Method, Rule parameters..., Functor). The Rule parameters are
forwarded to the constructor of the Rule that is created. This was
not documented.

The Functor is expected to follow some rules too. This is checked by
QHttpServerRouterViewTraits.

This change expresses the synatax in the function declaration as
(QString, Method, Functor) and removes the possibility to forward
parameters to the constructor of rule. The route method now returns a
pointer to the new rule, which can be used to set parameters instead.

Constraints to the Functor are still checked by QHttp...ViewTraits.

Pick-to: 6.8
Task-Id: QTBUG-128113
Change-Id: Id3d075a46e86169521bafd3ecb4c9c58ba8dff2c
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-08-27 20:18:50 +02:00
Lena Biliaieva ff870498f9 QHttpServerResponse: make API simpler by removing duplicating methods
Replaced all headers-related methods with only setter and getter to make
the class interface simpler and more consistent with other classes
consuming QHttpHeaders.

Resulted from API-review

Task-number: QTBUG-125859
Pick-to: 6.8
Change-Id: Ic41b471813969711bb07302a8929784bc425c84e
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-08-06 15:41:45 +02:00
Øystein Heskestad bd5ac90224 QAbstractHttpServer: Remove QSslConfiguration and listen() methods
To keep the API lean, remove the SSL confguration and listen()
methods.

Instead using listen() on a QAbstractHttpServer, a user should
create an instance of a QTcpServer or QSslServer, then call
listen() on it before calling bind() on a QAbstractHttpServer
with it as an argument.

Task-number: QTBUG-125859
Pick-to: 6.8
Change-Id: I366c0a01d8b7ee3802e0bdd63b9d84813338f478
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
2024-07-31 16:52:41 +02:00
Øystein Heskestad 19cf2bb2c7 Make tst_QHttpServer test HTTP 2 as well
Previously tst_QHttpServer only covered HTTP/1.1 and partially HTTPS/1.1.
Now all tst_QHttpServer tests are run for HTTP/1.1, HTTPS/1.1, and HTTP/2.

Fixes: QTBUG-122457
Pick-to: 6.8
Change-Id: I068a90545365a85e62e990a14bda38e43a4bbc64
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-07-25 12:59:36 +02:00
Øystein Heskestad bbc9e5deff Change QHttpServerResponder to be suitable for both HTTP 1.1 and 2
The QHttpServerResponder class is too low level and HTTP 1.1 specific
to be used for both HTTP 1.1 and 2. Remove the low level functions and
add member functions for sending data without having to know the
total length of the data before sending it.

To respond with data with length not known before response is
generated, call one of the writeBeginChunked functions, followed by
as many calls to writeChunk as needed, and finish with a call to one
of the writeEndChunked functions.

The HTTP 1.1 implementation has been moved from QHttpServerResponder
to QHttpServerResponderPrivate.

Fixes: QTBUG-124866
Change-Id: Ie4dd6982bbbb14a5403ebcdfe85626deb5fb2cc5
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
2024-05-13 14:29:07 +02:00
Lena Biliaieva bcfed45d9b Use QHttpHeaders in QHttpServerResponder
Fixes: QTBUG-120135
Change-Id: Ic0c60884b7bc1a05edf55c20b944268445c56e87
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
2024-02-21 15:36:55 +01:00
Lena Biliaieva 2c91877b7f Use QHttpHeaders in QHttpServerResponse
Added withHeaders() method to pass headers to the QHttpServerResponse object.
Removed methods using QHttpServerResponder::HeaderList because it will be also replaced by QHttpHeaders.
Added headers() method for convenience.
Updated tests and examples.

Fixes: QTBUG-107749
Change-Id: Ia9ce631a17b1b60e84ffc85e09215ac262407144
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
2024-02-13 13:03:08 +01:00
Ievgenii Meshcheriakov e47089a0e3 tst_QHttpServer::multipleResponses: Don't expect failure
The bug causing the failure (QTBUG-108068) was fixed.

Fixes: QTBUG-122154
Task-number: QTBUG-108068
Change-Id: I18d5b5a75b82947194fe68830cffaae1fe1f8fb6
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-02-12 11:00:27 +01:00
Ahmad Samir 9485e56429 Mark the whole repo with QT_NO_CONTEXTLESS_CONNECT
By adding it to the default build flags via .cmake.conf.

This amends commit  f0832a1fe4.

Change-Id: Idca0dedc94691eae5db9c844b16293e7064da509
Reviewed-by: Mikhail Svetkin <mikhail.svetkin@gmail.com>
2023-08-21 22:47:41 +03:00
Marcus Tillmanns a14ecdb0e6 Add support for local socket/server
Change-Id: I7be8f327535aa5f7b5156b42240043117d9107c0
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
2023-07-17 12:46:37 +00:00
Ievgenii Meshcheriakov 51c37b7ef7 Decay type passed to FunctionTraits
This allows for uniform handling of functions, function
pointers and function pointer references.

Update tst_qhttpserverrouter to use a static function in
addition to lambdas.

Update tst_qhttpserver to use lambda variables, functions,
function pointers, and a class with a custom call operator
for route handlers.

Fixes: QTBUG-112484
Pick-to: 6.5
Change-Id: I19713105c1bacf3365057b70d17e6211e05f8ab9
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-04-25 14:16:21 +02:00
Juha Vuolle 1308cb053b Remove few small compilation warnings
Pick-to: 6.5
Change-Id: I2693f05fe357f30767ecd7d901cdb9ff66fdeea3
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
2023-01-25 08:32:21 +02:00
Ievgenii Meshcheriakov d38ffaa0ac Remove QHttpServerResponse::write() and add QHttpServerResponder::writeResponse()
This allows to send more than a single response to a client.

Add an expected-failure (due to QTBUG-108068) test that produces
multiple responses.

[ChangeLog][QHttpServerResponse][Potentially Source-Incompatible Changes]
QHttpServerResponse::write() method was removed in favor of new
QHttpServerResponder::writeResponse().

Task-number: QTBUG-105202
Change-Id: I79f3297d1a4360634715be8593a6b146304d481f
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-11-14 11:16:02 +01:00
Ievgenii Meshcheriakov 55d10201dc Add connection tracking
Introduce private QHttpServerStream class that handles connection
state. This is the only class that contains a connected QTcpSocket.
Make other classes use QHttpServerResponder to communicate
with clients. Stop processing of further requests as long as a
QHttpServerResponder object for the current request is active.

Add a regression test to tst_qhttpserver.

[ChangeLog][Potentially Source-Incompatible Changes] Most public
methods that accepted a QTcpSocket are now accepting
QHttpServerResponder instead.

Task-number: QTBUG-105202
Change-Id: Ib8db7fdc65b59077411b09277f2b1948fde4848b
Reviewed-by: André Klitzing <aklitzing@gmail.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-11-14 11:15:59 +01:00
Lucie Gérard 0d8bb0465e Change the license of all CMakeLists.txt and *.cmake files to BSD
Task-number: QTBUG-105718
Change-Id: I6817ba90abea4ea72ad9d58bd17c825a38abb07f
Reviewed-by: Jörg Bornemann <joerg.bornemann@qt.io>
2022-08-25 16:10:12 +00:00
Ievgenii Meshcheriakov 9da514a0fa QAbstractHttpServer: Convert missingHandler() to a pure virtual method
This ensures that there is exactly one handler. This also should make
it easier to rework the response handling.

Pick-to: 6.4
Change-Id: I5771d94a0b2436b2ff2b745335184a80f4b2cf31
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-08-25 14:16:00 +02:00
Konrad Kujawa 70fff87eb2 Overload QHttpServerResponse with status codes
Add a status code to overloaded constructor of the QHttpServerResponse

Pick-to: 6.4
Fixes: QTBUG-105366
Change-Id: I3ac95df744484319e02ac6f7e24899e0b0368334
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
2022-08-10 08:39:26 +00:00
Ievgenii Meshcheriakov 02d9cd1da2 QHttpServerRequest: Cleanup Method enum
Add a value for TRACE method from RFC 7231.

Rename value All to AnyKnown.

Document the enum.

Fixes: QTBUG-105306
Task-number: QTBUG-100868
Pick-to: 6.4
Change-Id: Ibfc41d006df3dd7f2620cd9b2395b6b1b8ce6384
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-08-09 14:14:34 +00:00
Ievgenii Meshcheriakov 4a5c4487e7 tst_qhttpserver: Remove an unused #include of a private header
Also make the test non-private.

Pick-to: 6.4
Change-Id: I17eacc80e2b96443a4b8637d5e0df5bc88d583e2
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-08-09 16:14:31 +02:00
Ievgenii Meshcheriakov 1e8551ca16 QHttpServerLiterals: Inline literals in tests and unexport them
Also make tst_qhttpserverresponder and tst_qhttpserverresponse
public.

Pick-to: 6.4
Change-Id: I1b95d20c86799a6f1088e54599128b07f8290f6f
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Mikhail Svetkin <mikhail.svetkin@gmail.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-08-09 11:04:58 +02:00
Ievgenii Meshcheriakov aa0c7a54f9 Unexport private classes and functions
Use Q_AUTOTEST_EXPORT for stuff used by the tests.

Mark tst_qhttpser, tst_qhttpserverresponder and
tst_qhttpserverresponse as private because they are using
private APIs.

Task-number: QTBUG-100868
Pick-to: 6.4
Change-Id: I6ecee7ae76fe7e9dc9ab7eceb1ae1c74cc07ef79
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-08-08 13:09:01 +02:00
Ievgenii Meshcheriakov 9dccc52f4c QAbstractHttpServerPrivate: Fix reading of pipelined requests
The server socket may contain data for multiple requests
if the network client is performing HTTP pipelining.
This patch retriggers socket's readyRead() signal after
processing a request so that the server can handle next
pipelined request.

Pick-to: 6.4
Change-Id: Ifadd9cd5ff043b513ec7b831d4156d8ad5dece79
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-08-03 11:14:36 +02:00
Ievgenii Meshcheriakov 9363549ed0 QHttpServerRequest: Make headers() return a QtNetwork compatible type
Return QList<QPair<QByteArray, QByteArray>> instead of QVariantMap.

Task-number: QTBUG-100868
Pick-to: 6.4
Change-Id: I05da8b3ea15f1b7037d625c4d0ea320fca3e1016
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-07-29 15:32:19 +02:00
Ievgenii Meshcheriakov 9c69255f07 Remove support for supplying request methods as strings
This support was implemented by duplicating enum values for
QHttpServerRequest::Method. Among other things this causes
build errors on Windows due to Windows API defining DELETE.
There is also no compile time checking for valideness of
methods supplied as strings.

This partially reverts be06bd66b8.

Fixes: QTBUG-104710
Task-number: QTBUG-100868
Pick-to: 6.4
Change-Id: I47977c5979d00a1847a210b10c9f77f753880344
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-07-29 15:32:10 +02:00
Alexandru Croitor ed52c50fa0 CMake: Don't use PUBLIC_LIBRARIES for tests and test helpers
Change-Id: I7c6e4128b49afba63592462eaed56cbc668f6d9c
Reviewed-by: Alexey Edelev <alexey.edelev@qt.io>
2022-07-28 14:42:45 +02:00
Ievgenii Meshcheriakov 9b8f3a47ae Make QHttpServerResponse non-polymorphic
Remove QHttpServerFutureResponse and use QFuture<QHttpServerResponse>
instead.

Test for feature 'future' instead of 'concurrent' when only QFuture
is used.

Task-number: QTBUG-100868
Pick-to: 6.4
Change-Id: Iba318e89221afa69e46b3341ce222125421a22c6
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-07-26 09:28:06 +00:00
Ievgenii Meshcheriakov 12b2d70a0a Don't move out handler lambda when serving requests
Moving out the lambda may make it unusable for the subsequent requests.
Adjust the router API to use a const reference to the lambda.
Remove mutable annotation from the routeHandler lambda because it
is not needed anymore.

Add a regression test to verify the behavior.

Task-number: QTBUG-100868
Pick-to: 6.4
Change-Id: I19f91c6a61e9155378e5ff34cbdb9b27d09fce2c
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2022-07-22 16:26:11 +02:00
Ievgenii Meshcheriakov b7b27514b8 tst_qhttpserver: Link with QtConcurrent if available
This test is using QtConcurrent::run(). This call does not seem
to require linking with the library. But this is not documented,
so let's link anyway.

Task-number: QTBUG-100868
Pick-to: 6.4
Change-Id: I623133c478fdeda173cb9b7bcf6cd167f46526af
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2022-07-18 11:31:31 +02:00