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>
The number of QHttpServerRequest and QHttpServerResponder classes is
now called SpecialsCount instead of PlaceholdersCount. This makes more
sense because each parameter that is either QHttpServerRequest or
QHttpServerResponder is matched with IsSpecial in the traits templates.
Update the documentation to refer to specials instead of placeholders.
Task-number: QTBUG-129103
Change-Id: Iec7d5787d3693289bdf9bad9b3e0b7172fe08d2a
Reviewed-by: Matthias Rauter <matthias.rauter@qt.io>
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>
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>
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>
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>
That doesn't work when view handler is a function reference..
Task-number: QTBUG-112484
Pick-to: 6.5
Change-Id: I937cbd959123aa22b3dde4a30451f9f9e726bbab
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
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>
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>
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>
Adjust one test case to use such a lambda.
Fixes: QTBUG-104481
Task-number: QTBUG-100868
Pick-to: 6.4
Change-Id: I96e30fd167b8c2f8240316bff9c283efdb910541
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
The generic version works the same way as the zero arguments
specialization except for out-of-bound argument access.
Out-of-bound argument access was only used by tst_qhttpserverrouter
and is removed by this commit.
Task-number: QTBUG-100868
Pick-to: 6.4
Change-Id: I49b8d7623ed758b34f9726a497f86333d6002242
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
License files are organized under LICENSES directory.
Pick-to: 6.4
Task-number: QTBUG-67283
Change-Id: I657c36f679b9448ec68d411a492171bc39df1411
Reviewed-by: Jesus Fernandez <jsfdez@gmail.com>
They're already stored in unique_ptr internally, so use the more
expressive pass-unique_ptr-by-value idiom to express ownership
transfer, so the docs don't need to mention it anymore.
Also fixes a theoretical memleak on failed vector::emplace_back().
Pick-to: 6.4
Task-number: QTBUG-100868
Change-Id: I32e386378fe177e4890deea44f0e937c8054c1c6
Reviewed-by: Jesus Fernandez <jsfdez@gmail.com>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
- in route() implementations, the viewHandler was passed by universal
reference, however, it was then captured either by value (copying,
which some viewHandlers may not support) or - yuck - by reference,
creating a dangling pointer in case a temporary was passed. This
error was also present in the example implementations in the docs
and the test. To fix, std::forward the viewHandler into the mutable
lambda and std::move() it inside the lambda into
route.bindCaptured().
- One more case of RouterHandler being passed by rvalue ref and then
std::forward()ed, fixed by taking by value and std::move()ing
instead.
Pick-to: 6.4
Task-number: QTBUG-100868
Change-Id: I729f7e0c8fd0838679bcefc141fd5cea333d276b
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Jesus Fernandez <jsfdez@gmail.com>
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>
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>
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>
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>
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>