diff options
author | Lorn Potter <lorn.potter@gmail.com> | 2020-05-07 19:14:36 +1000 |
---|---|---|
committer | Lorn Potter <lorn.potter@gmail.com> | 2020-05-25 17:42:06 +1000 |
commit | 3fbf7b34cc2242559a047c3868855c9de6f0c3d3 (patch) | |
tree | 6c75d28faae21441cb1daffcc15794784a2320b5 /src/network/access | |
parent | 745a7fa31e3e56a9c645334811b8f4298d680323 (diff) |
wasm: set status codes from network operation
Pick-to: 5.15
Fixes: QTBUG-83991
Change-Id: Ie1e88189bee8b6a9dc6cb2a721777a5e1032307a
Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
Diffstat (limited to 'src/network/access')
-rw-r--r-- | src/network/access/qnetworkreplywasmimpl.cpp | 27 | ||||
-rw-r--r-- | src/network/access/qnetworkreplywasmimpl_p.h | 2 |
2 files changed, 20 insertions, 9 deletions
diff --git a/src/network/access/qnetworkreplywasmimpl.cpp b/src/network/access/qnetworkreplywasmimpl.cpp index 73fd139607..94c2106a15 100644 --- a/src/network/access/qnetworkreplywasmimpl.cpp +++ b/src/network/access/qnetworkreplywasmimpl.cpp @@ -454,15 +454,21 @@ void QNetworkReplyWasmImplPrivate::_q_bufferOutgoingData() void QNetworkReplyWasmImplPrivate::downloadSucceeded(emscripten_fetch_t *fetch) { - QByteArray buffer(fetch->data, fetch->numBytes); - QNetworkReplyWasmImplPrivate *reply = reinterpret_cast<QNetworkReplyWasmImplPrivate*>(fetch->userData); if (reply) { + QByteArray buffer(fetch->data, fetch->numBytes); reply->dataReceived(buffer, buffer.size()); } } +void QNetworkReplyWasmImplPrivate::setStatusCode(int status, const QByteArray &statusText) +{ + Q_Q(QNetworkReplyWasmImpl); + q->setAttribute(QNetworkRequest::HttpStatusCodeAttribute, status); + q->setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, statusText); +} + void QNetworkReplyWasmImplPrivate::stateChange(emscripten_fetch_t *fetch) { if (fetch->readyState == /*HEADERS_RECEIVED*/ 2) { @@ -488,14 +494,17 @@ void QNetworkReplyWasmImplPrivate::downloadProgress(emscripten_fetch_t *fetch) void QNetworkReplyWasmImplPrivate::downloadFailed(emscripten_fetch_t *fetch) { QNetworkReplyWasmImplPrivate *reply = reinterpret_cast<QNetworkReplyWasmImplPrivate*>(fetch->userData); - Q_ASSERT(reply); - - QString reasonStr = QString::fromUtf8(fetch->statusText); - - reply->setReplyAttributes(reinterpret_cast<quintptr>(fetch->userData), fetch->status, reasonStr); - - if (fetch->status >= 400 && !reasonStr.isEmpty()) + if (reply) { + QString reasonStr; + if (fetch->status > 600 || reply->state == QNetworkReplyPrivate::Aborted) + reasonStr = QStringLiteral("Operation canceled"); + else + reasonStr = QString::fromUtf8(fetch->statusText); + + QByteArray statusText(fetch->statusText); + reply->setStatusCode(fetch->status, statusText); reply->emitReplyError(reply->statusCodeFromHttp(fetch->status, reply->request.url()), reasonStr); + } if (fetch->status >= 400) emscripten_fetch_close(fetch); // Also free data on failure. diff --git a/src/network/access/qnetworkreplywasmimpl_p.h b/src/network/access/qnetworkreplywasmimpl_p.h index 3c18342c6c..0a62e8ad37 100644 --- a/src/network/access/qnetworkreplywasmimpl_p.h +++ b/src/network/access/qnetworkreplywasmimpl_p.h @@ -112,6 +112,8 @@ public: void dataReceived(const QByteArray &buffer, int bufferSize); void headersReceived(const QByteArray &buffer); + void setStatusCode(int status, const QByteArray &statusText); + void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData); |