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>
This commit is contained in:
parent
745a7fa31e
commit
3fbf7b34cc
@ -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);
|
||||
if (reply) {
|
||||
QString reasonStr;
|
||||
if (fetch->status > 600 || reply->state == QNetworkReplyPrivate::Aborted)
|
||||
reasonStr = QStringLiteral("Operation canceled");
|
||||
else
|
||||
reasonStr = QString::fromUtf8(fetch->statusText);
|
||||
|
||||
QString reasonStr = QString::fromUtf8(fetch->statusText);
|
||||
|
||||
reply->setReplyAttributes(reinterpret_cast<quintptr>(fetch->userData), fetch->status, reasonStr);
|
||||
|
||||
if (fetch->status >= 400 && !reasonStr.isEmpty())
|
||||
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.
|
||||
|
@ -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);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user