diff options
-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); |