16 Commits

Author SHA1 Message Date
Marc Mutz
8302c727e6 QRestReply: make charset parsing more robust
The old code was based on QString::split and e.g. didn't handle
escapes in quoted-strings.

Write a modern recursive-descent parser to parse out type/subtype and
charset parameter. Since we don't, yet, support CFWS (see below),
recursion depth is strictly limited, so we're not susceptible to
recursion bombs here.

It currently handles only RFC9110-style grammar, but can be easily
extended to support CFWS (RFC2822-style comments and folding
white-space) or RFC2231-style continuuations, if needed.

It's a bit more general than strictly required, because I expect this
to be reused elsewhere ere long.

Manual conflict resolutions:
 - dropped a few constexpr from functions which use QByteArrayView's
   startsWith(), which is only constexpr since 6.8

Fixes: QTBUG-120307
Change-Id: I309928dc350a043672dffb4a259b457764c031be
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
(cherry picked from commit 98b034e53a7821018683c05d5dba776f0f2753f0)
2024-05-02 05:34:25 +00:00
Marc Mutz
0eaf2e9df8 QRestReply: micro-optimize optional<QStringDecoder> handling
Use optional::emplace() instead of assignment from an rvalue.

Saves the move constructor and destructor calls, both of which are not
trivial (due to cleanFn).

Change-Id: Ief77626c77d0c8c2ce17e3b1a21496a7da969761
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
(cherry picked from commit 063e31209b1750b6cbd2c3f57c49ce372b13a91a)
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2024-04-24 16:25:26 +00:00
Marc Mutz
40a11d7eba QRestReply: fix "No relevant classes found." moc warning
QRestReply is no longer a QObject, so remove the includemocs line from
the .cpp file.

Amends 9ba5c7ff6aa42c5701cf950d2137467a2d178833.

Change-Id: I6c0ba6b9e3b82f84f3b509755e7da5b33e607776
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
(cherry picked from commit 2ff93ea0eeddc9c4c01c194e5af2a2c4506a9d9e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-03-14 13:48:27 +00:00
Juha Vuolle
d134378b20 Remove unsused includes in QRestReply
The removed includes were needed when there were separate methods
for returning QJsonArray and QJsonObject

Change-Id: I5f08c4afd5487c5ca191ee813a3d94c4ae3b0f06
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit ab04dcca88f926b6512acb7bd108eccb100d3b2e)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-03-01 21:05:45 +00:00
Jaishree Vyas
08868b1c4b Doc: Documentation improvement in QHttpHeaders and REST classes
Language and some other improvisations

Fixes: QTBUG-120028
Change-Id: Id5a5544abf244de5cff83f0d795732595934bd36
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
(cherry picked from commit d7b71294e8267123595593efca397151e4bf2595)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-02-29 10:48:36 +00:00
Juha Vuolle
7f50c19152 Rename QRestReply data accessors as read* functions
This naming should make it clearer that (successful) calls to
readJson(), readBody(), and readText() consume the data received
so far.

Resulted from API-review

Change-Id: I09ca9eac598f8fc83eecb72c22431ac35b966bf5
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit bd78ff024599d33cfcb411ff17727a0f4447bc7e)
2024-01-31 13:36:56 +02:00
Juha Vuolle
7fd767478a Update QRestReply documentation
To accommodate the deduplication and non-owning changes
in previous commit.

Resulted from API-review

Change-Id: Ie1c4e9959c1ba7e8ed2be6607d9f6497ae15af39
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
(cherry picked from commit efa178d42c5e9e8c6dc526430f201f16a67149c3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-01-30 10:17:41 +00:00
Juha Vuolle
afc1f2a6cc Make QRest* APIs non-owning and non-duplicating
Note: documentation will be updated in a follow-up commit

This commit makes QRestReply and QRestAccessManager
classes lighter, non-owning wrappers. Furthermore their
APIs don't duplicate the wrapped QNetwork* APIs.

This makes it easier to use / opt-in to these helpers
in pre-existing applications which are based on
QNetworkAccessManager and QNetworkReply.

Since APIs are no longer duplicated, the QRest
classes are more obviously a convenience _wrapper_,
as opposed to being an alternative vertical stack.

In practice this change consists of:
- QRestAM never instantiates QNetworkAccessManager,
  but accepts it via constructor. It does not take
  ownership of the QNetworkAccessManager.
- QRestReply accepts QNetworkReply via constructor. It
  does not take ownership of the QNetworkReply
- Signals and most duplicated functions are removed
  from both QRestAM and QRR.
- QRestReply is no longer a QObject
- Since QRestAM doesn't have much to report anymore,
  the debug operator is dropped.

Resulted from API-review

Change-Id: Ib62d9cc2df41cac631396a84bb7ec4d2d54b0c8c
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 9ba5c7ff6aa42c5701cf950d2137467a2d178833)
2024-01-30 12:17:31 +02:00
Marc Mutz
a915e2b211 QRestReply: optionally return the QJsonParseError from json()
... and remove the debug output of the internal QJsonParseError.

This allows users of the function to get the details in
machine-readable form, and to distinguish between !finished and an
actual Json parsing error.

Found in API-review.

Change-Id: Ia237b192a894d692b965f6bedb4c94d3b6537535
Reviewed-by: Juha Vuolle <juha.vuolle@qt.io>
(cherry picked from commit 3a61de282c4740efe4a6fa1672e66efaf7c2b408)
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
2024-01-16 06:06:27 +01:00
Juha Vuolle
b7e793f627 Add streaming text support to QRestReply
Provides the possibility to read text data as it arrives, instead
of needing to wait until the whole body is received.

Task-number: QTBUG-119002
Change-Id: I64f90148fd41a77c4ae2d5dbd6194a924a9f3a86
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
(cherry picked from commit 4da14a67a6157c415f8228a8bae7d6b0f895df7c)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-01-15 06:01:15 +00:00
Juha Vuolle
980b57e85c Change QRestReply json return type to QJsonDocument
The json return type and function naming has gone back
and forth. Let's go with QJsonDocument after all, and add new
overloads in future if necessary.

Task-number: QTBUG-119002
Change-Id: I3f9de0e6cba7d5c52d016d252d65b81f345af050
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
(cherry picked from commit 1702a37a3955f449210fe3874cfcd35bb08417ad)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
2024-01-12 11:05:50 +00:00
Juha Vuolle
11b19b3341 Mark REST helper classes as tech preview
Task-number: QTBUG-119002
Change-Id: Icf4d50b0e6f25e4e5f82df0b23a249332bbf55bf
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-12-08 15:53:36 +02:00
Juha Vuolle
0f34316fb7 Add QDebug support for QRestReply
Task-number: QTBUG-114705
Change-Id: I6c355d683389b773082c5966434d733bf5aec506
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-12-08 15:53:35 +02:00
Juha Vuolle
298d5a4bbd Add uploadProgress signal for QRestReply
Task-number: QTBUG-114717
Change-Id: I2052e4cc4da90962483f5f1931dc20552e484e34
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-12-08 15:53:34 +02:00
Juha Vuolle
e9f703ed3b Add signals and methods for QRestReply download progress
These include:
- readyRead(), signal for indicating new data availability
- bytesAvailable(), function for checking available data amount
- downloadProgress(), signal for monitoring download progress

Task-number: QTBUG-114717
Change-Id: Id6c49530d7857f5c76bd111eba84525137294ea7
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-12-08 15:53:33 +02:00
Juha Vuolle
e560adef21 Add REST client convenience wrappers
[ChangeLog][QtNetwork][QRestAccessManager] Added new convenience
classes QRestAccessManager and QRestReply for typical RESTful
client application usage

Task-number: QTBUG-114637
Task-number: QTBUG-114701
Change-Id: I65057e56bf27f365b54bfd528565efd5f09386aa
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
Reviewed-by: Mate Barany <mate.barany@qt.io>
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
2023-12-08 15:53:33 +02:00