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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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 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>
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>
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>
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>
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>
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>
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>
Forward-declare the used classes instead in the header and include them
in the corresponding source file.
Task-number: QTBUG-100868
Pick-to: 6.4
Change-Id: I10a288818df6cad0b089351816f0a2d0eb9c012d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Generates less code, and we may be able to remove QDebug includes.
Some uses aren't easily ported, leave them as ostream-style.
Also prefer %ls/qUtf16Printable() over %s/qPrintable() (again: less
code).
Pick-to: 6.4
Task-number: QTBUG-100868
Change-Id: I812bed2ecfeb5776155ff5f95320d6accc5974d3
Reviewed-by: Ievgenii Meshcheriakov <ievgenii.meshcheriakov@qt.io>
Reviewed-by: Jesus Fernandez <jsfdez@gmail.com>
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>
- 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>
- replace with QLatin1StringView
- take by value, not by cref
- in one case, replace with a char16_t, because size() == 1
Pick-to: 6.4
Task-number: QTBUG-100868
Change-Id: Ib1d9c3058d3dc9aad560b27bda89b7dc1f897dbb
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Jesus Fernandez <jsfdez@gmail.com>
Always ignore the same set of errors instead. At least on macOS it
is possible to compile Qt with OpenSSL support but don't have it
at runtime.
Fixes: QTBUG-100479
Change-Id: I213de297f840e6ef344fc87317103a9766f0598b
Reviewed-by: Jesus Fernandez <jsfdez@gmail.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Current openssl versions do not accept secret keys shorter than
2048 by default. This causes tests with 1024 bytes key to fail.
This commit replaces the certificate/key pair with new one with
the key length of 4096 that should be good enough for some time.
Fixes: QTBUG-100479
Change-Id: I185812e867eae2c6295cb28df229785f91fc99f2
Reviewed-by: Jesus Fernandez <jsfdez@gmail.com>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Provide simple API for asynchronous resoponses
Change-Id: Ic0c92cce95751dc8f9d6b0dfa96e39019f5f5e9e
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
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>
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>
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>
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>
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>
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>
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>
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>