Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qnetworkreplywasmimpl.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:critical reason:data-parser
4
7
8#include <QtCore/qdatetime.h>
9#include <QtCore/qcoreapplication.h>
10#include <QtCore/qfileinfo.h>
11#include <QtCore/qthread.h>
12#include <QtCore/private/qwasmglobal_p.h>
13#include <QtCore/private/qoffsetstringarray_p.h>
14#include <QtCore/private/qtools_p.h>
15
16#include <private/qnetworkaccessmanager_p.h>
17#include <private/qnetworkfile_p.h>
18
19#include <emscripten.h>
20#include <emscripten/fetch.h>
21
23
24using namespace Qt::StringLiterals;
25
26namespace {
27
28static constexpr auto BannedHeaders = qOffsetStringArray(
29 "accept-charset",
30 "accept-encoding",
31 "access-control-request-headers",
32 "access-control-request-method",
33 "connection",
34 "content-length",
35 "cookie",
36 "cookie2",
37 "date",
38 "dnt",
39 "expect",
40 "host",
41 "keep-alive",
42 "origin",
43 "referer",
44 "te",
45 "trailer",
46 "transfer-encoding",
47 "upgrade",
48 "via"
49);
50
51bool isUnsafeHeader(QLatin1StringView header) noexcept
52{
53 return header.startsWith("proxy-"_L1, Qt::CaseInsensitive)
54 || header.startsWith("sec-"_L1, Qt::CaseInsensitive)
55 || BannedHeaders.contains(header, Qt::CaseInsensitive);
56}
57} // namespace
58
70
90
91QNetworkReplyWasmImpl::QNetworkReplyWasmImpl(QObject *parent)
92 : QNetworkReply(*new QNetworkReplyWasmImplPrivate(), parent)
93{
94 Q_D( QNetworkReplyWasmImpl);
95 d->state = QNetworkReplyPrivate::Idle;
96}
97
99{
100 if (isRunning())
101 abort();
102 close();
103}
104
105QByteArray QNetworkReplyWasmImpl::methodName() const
106{
107 const Q_D( QNetworkReplyWasmImpl);
108 switch (operation()) {
109 case QNetworkAccessManager::HeadOperation:
110 return "HEAD";
111 case QNetworkAccessManager::GetOperation:
112 return "GET";
113 case QNetworkAccessManager::PutOperation:
114 return "PUT";
115 case QNetworkAccessManager::PostOperation:
116 return "POST";
117 case QNetworkAccessManager::DeleteOperation:
118 return "DELETE";
119 case QNetworkAccessManager::CustomOperation:
120 return d->request.attribute(QNetworkRequest::CustomVerbAttribute).toByteArray();
121 default:
122 break;
123 }
124 return QByteArray();
125}
126
128{
129 Q_D(QNetworkReplyWasmImpl);
130
131 if (!d->m_fetch)
132 return;
133 d->closeFetch();
134 if (d->state != QNetworkReplyPrivate::Aborted &&
135 d->state != QNetworkReplyPrivate::Finished &&
136 d->state != QNetworkReplyPrivate::Idle) {
137 d->state = QNetworkReplyPrivate::Finished;
138 d->setCanceled();
139 }
140 QNetworkReply::close();
141}
142
144{
145 Q_D(QNetworkReplyWasmImpl);
146
147 if (d->state == QNetworkReplyPrivate::Finished || d->state == QNetworkReplyPrivate::Aborted)
148 return;
149
150 d->state = QNetworkReplyPrivate::Aborted;
151 d->setCanceled();
152}
153
155{
156 Q_Q(QNetworkReplyWasmImpl);
157 {
158 if (m_fetchContext) {
159 std::scoped_lock lock{ m_fetchContext->mutex };
163 }
164 }
165
167 emitReplyError(QNetworkReply::OperationCanceledError, QStringLiteral("Operation canceled"));
168 q->setFinished(true);
169 emit q->finished();
170}
171
173{
174 emscripten_fetch_t *fetch = m_fetch;
175 if (!fetch)
176 return;
177 m_fetch = nullptr;
178 // The fetch is created on and owned by the main thread (see doSendRequest),
179 // so it must be closed there. Closing it from a worker thread cannot find the
180 // XHR handle and frees the fetch struct while the main thread still uses it.
181 qwasmglobal::runOnMainThreadAsync([fetch]() { emscripten_fetch_close(fetch); });
182}
183
185{
186 Q_D(const QNetworkReplyWasmImpl);
187
188 return QNetworkReply::bytesAvailable() + d->downloadBuffer.size() - d->downloadBufferReadPosition;
189}
190
192{
193 return true;
194}
195
197{
198 return QNetworkReply::size();
199}
200
201/*!
202 \internal
203*/
204qint64 QNetworkReplyWasmImpl::readData(char *data, qint64 maxlen)
205{
206 Q_D(QNetworkReplyWasmImpl);
207
208 qint64 howMuch = qMin(maxlen, (d->downloadBuffer.size() - d->downloadBufferReadPosition));
209 if (howMuch <= 0)
210 return 0;
211 memcpy(data, d->downloadBuffer.constData() + d->downloadBufferReadPosition, howMuch);
212 d->downloadBufferReadPosition += howMuch;
213
214 // Drop the bytes already handed out so the streamed buffer does not grow
215 // unbounded over the lifetime of the transfer.
216 d->downloadBuffer.remove(0, d->downloadBufferReadPosition);
217 d->downloadBufferReadPosition = 0;
218
219 return howMuch;
220}
221
222void QNetworkReplyWasmImplPrivate::setup(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *data)
223{
224 Q_Q(QNetworkReplyWasmImpl);
225
226 outgoingData = data;
227 request = req;
228 url = request.url();
229 operation = op;
230
231 q->QIODevice::open(QIODevice::ReadOnly);
232 if (outgoingData && outgoingData->isSequential()) {
233 bool bufferingDisallowed =
234 request.attribute(QNetworkRequest::DoNotBufferUploadDataAttribute, false).toBool();
235
236 if (bufferingDisallowed) {
237 // if a valid content-length header for the request was supplied, we can disable buffering
238 // if not, we will buffer anyway
239 if (!request.header(QNetworkRequest::ContentLengthHeader).isValid()) {
242 return;
243 }
244 } else {
245 // doSendRequest will be called when the buffering has finished.
248 return;
249 }
250 }
251 // No outgoing data (POST, ..)
253}
254
255void QNetworkReplyWasmImplPrivate::setReplyAttributes(quintptr data, int statusCode, const QString &statusReason)
256{
257 QNetworkReplyWasmImplPrivate *handler = reinterpret_cast<QNetworkReplyWasmImplPrivate*>(data);
258 Q_ASSERT(handler);
259
260 handler->q_func()->setAttribute(QNetworkRequest::HttpStatusCodeAttribute, statusCode);
261 if (!statusReason.isEmpty())
262 handler->q_func()->setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, statusReason);
263}
264
265constexpr int getArraySize (int factor) {
266 return 2 * factor + 1;
267}
268
270{
271 Q_Q(QNetworkReplyWasmImpl);
272 totalDownloadSize = 0;
273
274 emscripten_fetch_attr_t attr;
275 emscripten_fetch_attr_init(&attr);
276 qstrncpy(attr.requestMethod, q->methodName().constData(), 32); // requestMethod is char[32] in emscripten
277
278 attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY | EMSCRIPTEN_FETCH_STREAM_DATA;
279
280 QNetworkRequest::CacheLoadControl CacheLoadControlAttribute =
281 (QNetworkRequest::CacheLoadControl)request.attribute(QNetworkRequest::CacheLoadControlAttribute, QNetworkRequest::PreferNetwork).toInt();
282
283 if (CacheLoadControlAttribute == QNetworkRequest::AlwaysCache) {
284 attr.attributes += EMSCRIPTEN_FETCH_NO_DOWNLOAD;
285 }
286 if (CacheLoadControlAttribute == QNetworkRequest::PreferCache) {
287 attr.attributes += EMSCRIPTEN_FETCH_APPEND;
288 }
289
290 attr.withCredentials = request.attribute(QNetworkRequest::UseCredentialsAttribute, false).toBool();
291 attr.onsuccess = QNetworkReplyWasmImplPrivate::downloadSucceeded;
292 attr.onerror = QNetworkReplyWasmImplPrivate::downloadFailed;
293 attr.onprogress = QNetworkReplyWasmImplPrivate::downloadProgress;
294 attr.onreadystatechange = QNetworkReplyWasmImplPrivate::stateChange;
295 attr.timeoutMSecs = request.transferTimeout();
296
298 attr.userData = static_cast<void *>(m_fetchContext);
299 if (outgoingData) { // data from post request
300 m_fetchContext->requestData = outgoingData->readAll(); // is there a size restriction here?
301 if (!m_fetchContext->requestData.isEmpty()) {
302 attr.requestData = m_fetchContext->requestData.data();
303 attr.requestDataSize = m_fetchContext->requestData.size();
304 }
305 }
306
307 qwasmglobal::runOnMainThread([attr, fetchContext = m_fetchContext]() mutable {
308 std::unique_lock lock{ fetchContext->mutex };
309 if (fetchContext->state == FetchContext::State::CANCELED) {
310 fetchContext->state = FetchContext::State::FINISHED;
311 return;
312 } else if (fetchContext->state == FetchContext::State::TO_BE_DESTROYED) {
313 lock.unlock();
314 delete fetchContext;
315 return;
316 }
317 const auto reply = fetchContext->reply;
318 const auto &request = reply->request;
319
320 QByteArray userName, password;
321 if (!request.url().userInfo().isEmpty()) {
322 userName = request.url().userName().toUtf8();
323 password = request.url().password().toUtf8();
324 attr.userName = userName.constData();
325 attr.password = password.constData();
326 }
327
328 QList<QByteArray> headersData = request.rawHeaderList();
329 int arrayLength = getArraySize(headersData.count());
330 const char *customHeaders[arrayLength];
331 QStringList trimmedHeaders;
332 if (headersData.count() > 0) {
333 int i = 0;
334 for (const auto &headerName : headersData) {
335 if (isUnsafeHeader(QLatin1StringView(headerName.constData()))) {
336 trimmedHeaders.push_back(QString::fromLatin1(headerName));
337 } else {
338 customHeaders[i++] = headerName.constData();
339 customHeaders[i++] = request.rawHeader(headerName).constData();
340 }
341 }
342 if (!trimmedHeaders.isEmpty()) {
343 qWarning() << "Qt has trimmed the following forbidden headers from the request:"
344 << trimmedHeaders.join(QLatin1StringView(", "));
345 }
346 customHeaders[i] = nullptr;
347 attr.requestHeaders = customHeaders;
348 }
349
350 auto url = request.url().toString().toUtf8();
351 QString dPath = "/home/web_user/"_L1 + request.url().fileName();
352 QByteArray destinationPath = dPath.toUtf8();
353 attr.destinationPath = destinationPath.constData();
354 reply->m_fetch = emscripten_fetch(&attr, url.constData());
355 fetchContext->state = FetchContext::State::SENT;
356 });
357 state = Working;
358}
359
360void QNetworkReplyWasmImplPrivate::emitReplyError(QNetworkReply::NetworkError errorCode, const QString &errorString)
361{
362 Q_Q(QNetworkReplyWasmImpl);
363
364 q->setError(errorCode, errorString);
365 emit q->errorOccurred(errorCode);
366}
367
368void QNetworkReplyWasmImplPrivate::emitDataReadProgress(qint64 bytesReceived, qint64 bytesTotal)
369{
370 Q_Q(QNetworkReplyWasmImpl);
371
372 totalDownloadSize = bytesTotal;
373
374 percentFinished = bytesTotal ? (bytesReceived / bytesTotal) * 100 : 100;
375
376 emit q->downloadProgress(bytesReceived, bytesTotal);
377}
378
380{
381 Q_Q(QNetworkReplyWasmImpl);
382
383 const qsizetype bufferSize = buffer.size();
384 if (bufferSize == 0)
385 return;
386
387 // Called once per streamed chunk, so accumulate rather than overwrite.
388 bytesDownloaded += bufferSize;
389 downloadBufferCurrentSize += bufferSize;
390 totalDownloadSize = downloadBufferCurrentSize;
391
392 downloadBuffer.append(buffer);
393
394 emit q->readyRead();
395}
396
397//taken from qnetworkrequest.cpp
398static int parseHeaderName(const QByteArray &headerName)
399{
400 if (headerName.isEmpty())
401 return -1;
402
403 auto is = [&](const char *what) {
404 return qstrnicmp(headerName.data(), headerName.size(), what) == 0;
405 };
406
407 switch (QtMiscUtils::toAsciiLower(headerName.front())) {
408 case 'c':
409 if (is("content-type"))
410 return QNetworkRequest::ContentTypeHeader;
411 else if (is("content-length"))
412 return QNetworkRequest::ContentLengthHeader;
413 else if (is("cookie"))
414 return QNetworkRequest::CookieHeader;
415 break;
416
417 case 'l':
418 if (is("location"))
419 return QNetworkRequest::LocationHeader;
420 else if (is("last-modified"))
421 return QNetworkRequest::LastModifiedHeader;
422 break;
423
424 case 's':
425 if (is("set-cookie"))
426 return QNetworkRequest::SetCookieHeader;
427 else if (is("server"))
428 return QNetworkRequest::ServerHeader;
429 break;
430
431 case 'u':
432 if (is("user-agent"))
433 return QNetworkRequest::UserAgentHeader;
434 break;
435 }
436
437 return -1; // nothing found
438}
439
440
442{
443 Q_Q(QNetworkReplyWasmImpl);
444
445 if (!buffer.isEmpty()) {
446 QList<QByteArray> headers = buffer.split('\n');
447
448 for (auto &&header : headers) {
449 if (auto splitPos = header.indexOf(':');
450 splitPos != -1) { // headers include final \x00, so skip
451 auto headerName = header.first(splitPos).trimmed();
452 auto headerValue = header.sliced(splitPos + 1).trimmed();
453 headerValue = headerValue.replace('\x00', "").trimmed();
454
455 if (headerName.isEmpty() || headerValue.isEmpty())
456 continue;
457
458 int headerIndex = parseHeaderName(headerName);
459
460 if (headerIndex == -1)
461 q->setRawHeader(headerName, headerValue);
462 else
463 q->setHeader(static_cast<QNetworkRequest::KnownHeaders>(headerIndex),
464 (QVariant)headerValue);
465 }
466 }
467 }
468 emit q->metaDataChanged();
469}
470
472{
473 Q_Q(QNetworkReplyWasmImpl);
474
475 // make sure this is only called once, ever.
476 //_q_bufferOutgoingData may call it or the readChannelFinished emission
477 if (state != Buffering)
478 return;
479
480 // disconnect signals
481 QObject::disconnect(outgoingData, SIGNAL(readyRead()), q, SLOT(_q_bufferOutgoingData()));
482 QObject::disconnect(outgoingData, SIGNAL(readChannelFinished()), q, SLOT(_q_bufferOutgoingDataFinished()));
483
484 // finally, start the request
486}
487
489{
490 Q_Q(QNetworkReplyWasmImpl);
491
492 if (!outgoingDataBuffer) {
493 // first call, create our buffer
494 outgoingDataBuffer = std::make_shared<QRingBuffer>();
495
496 QObject::connect(outgoingData, SIGNAL(readyRead()), q, SLOT(_q_bufferOutgoingData()));
497 QObject::connect(outgoingData, SIGNAL(readChannelFinished()), q, SLOT(_q_bufferOutgoingDataFinished()));
498 }
499
500 qint64 bytesBuffered = 0;
501 qint64 bytesToBuffer = 0;
502
503 // read data into our buffer
504 forever {
505 bytesToBuffer = outgoingData->bytesAvailable();
506 // unknown? just try 2 kB, this also ensures we always try to read the EOF
507 if (bytesToBuffer <= 0)
508 bytesToBuffer = 2*1024;
509
510 char *dst = outgoingDataBuffer->reserve(bytesToBuffer);
511 bytesBuffered = outgoingData->read(dst, bytesToBuffer);
512
513 if (bytesBuffered == -1) {
514 // EOF has been reached.
515 outgoingDataBuffer->chop(bytesToBuffer);
516
517 _q_bufferOutgoingDataFinished();
518 break;
519 } else if (bytesBuffered == 0) {
520 // nothing read right now, just wait until we get called again
521 outgoingDataBuffer->chop(bytesToBuffer);
522
523 break;
524 } else {
525 // don't break, try to read() again
526 outgoingDataBuffer->chop(bytesToBuffer - bytesBuffered);
527 }
528 }
529}
530
531void QNetworkReplyWasmImplPrivate::downloadSucceeded(emscripten_fetch_t *fetch)
532{
533 auto fetchContext = static_cast<FetchContext *>(fetch->userData);
534 std::unique_lock lock{ fetchContext->mutex };
535
536 if (fetchContext->state == FetchContext::State::TO_BE_DESTROYED) {
537 lock.unlock();
538 delete fetchContext;
539 return;
540 } else if (fetchContext->state == FetchContext::State::CANCELED) {
541 fetchContext->state = FetchContext::State::FINISHED;
542 return;
543 } else if (fetchContext->state == FetchContext::State::SENT) {
544 const auto reply = fetchContext->reply;
545 if (reply->state != QNetworkReplyPrivate::Aborted) {
546 int status = fetch->status;
547 QByteArray statusText(fetch->statusText);
548 // With EMSCRIPTEN_FETCH_STREAM_DATA the body has already been handed
549 // over chunk by chunk in downloadProgress, so nothing is read here.
550 // Finish on the reply's own thread, callbacks run on the main thread.
551 QMetaObject::invokeMethod(reply->q_func(), [reply, status, statusText]() {
552 reply->setStatusCode(status, statusText);
553 reply->setReplyFinished();
554 }, Qt::QueuedConnection);
555 }
556 reply->m_fetch = nullptr;
557 fetchContext->state = FetchContext::State::FINISHED;
558 emscripten_fetch_close(fetch); // free the fetch struct and its data buffer
559 }
560}
561
563{
564 Q_Q(QNetworkReplyWasmImpl);
566 q->setFinished(true);
567 emit q->readChannelFinished();
568 emit q->finished();
569}
570
571void QNetworkReplyWasmImplPrivate::setStatusCode(int status, const QByteArray &statusText)
572{
573 Q_Q(QNetworkReplyWasmImpl);
574 q->setAttribute(QNetworkRequest::HttpStatusCodeAttribute, status);
575 q->setAttribute(QNetworkRequest::HttpReasonPhraseAttribute, statusText);
576}
577
578void QNetworkReplyWasmImplPrivate::stateChange(emscripten_fetch_t *fetch)
579{
580 auto fetchContext = static_cast<FetchContext*>(fetch->userData);
581 std::scoped_lock lock{ fetchContext->mutex };
582 const auto reply = fetchContext->reply;
583 if (!reply || fetchContext->state != FetchContext::State::SENT
584 || reply->state == QNetworkReplyPrivate::Aborted) {
585 return;
586 }
587 if (fetch->readyState != /*HEADERS_RECEIVED*/ 2)
588 return;
589
590 const int status = fetch->status;
591 size_t headerLength = emscripten_fetch_get_response_headers_length(fetch);
592 QByteArray str(headerLength, Qt::Uninitialized);
593 emscripten_fetch_get_response_headers(fetch, str.data(), str.size());
594 // Deliver headers on the reply's own thread, callbacks run on the main thread.
595 // The status code is set with them, the reason phrase follows when the reply finishes.
596 QMetaObject::invokeMethod(reply->q_func(), [reply, status, str]() {
597 reply->q_func()->setAttribute(QNetworkRequest::HttpStatusCodeAttribute, status);
598 reply->headersReceived(str);
599 }, Qt::QueuedConnection);
600}
601
602void QNetworkReplyWasmImplPrivate::downloadProgress(emscripten_fetch_t *fetch)
603{
604 auto fetchContext = static_cast<FetchContext*>(fetch->userData);
605 std::scoped_lock lock{ fetchContext->mutex };
606 const auto reply = fetchContext->reply;
607 if (!reply || fetchContext->state != FetchContext::State::SENT
608 || reply->state == QNetworkReplyPrivate::Aborted) {
609 return;
610 }
611
612 uint64_t bytes = fetch->dataOffset + fetch->numBytes;
613 uint64_t tBytes = fetch->totalBytes; // totalBytes can be 0 if server not reporting content length
614 if (tBytes == 0)
615 tBytes = bytes;
616 // Error responses deliver their body as well, but report no download progress.
617 const bool reportProgress = fetch->status < 400;
618 // With EMSCRIPTEN_FETCH_STREAM_DATA fetch->data points at the newest chunk of
619 // length numBytes, copy it out now as the pointer is only valid for this call.
620 QByteArray chunk;
621 if (fetch->data && fetch->numBytes > 0)
622 chunk = QByteArray(fetch->data, fetch->numBytes);
623
624 // Fetch callbacks run on the main thread while the reply may live on another
625 // thread, so deliver the chunk and progress on the reply's own thread.
626 QMetaObject::invokeMethod(reply->q_func(), [reply, chunk, bytes, tBytes, reportProgress]() {
627 if (!chunk.isEmpty())
628 reply->dataReceived(chunk);
629 if (reportProgress)
630 reply->emitDataReadProgress(bytes, tBytes);
631 }, Qt::QueuedConnection);
632}
633
634void QNetworkReplyWasmImplPrivate::downloadFailed(emscripten_fetch_t *fetch)
635{
636 const auto fetchContext = static_cast<FetchContext*>(fetch->userData);
637 std::unique_lock lock{ fetchContext->mutex };
638
639 if (fetchContext->state == FetchContext::State::TO_BE_DESTROYED) {
640 lock.unlock();
641 delete fetchContext;
642 return;
643 } else if (fetchContext->state == FetchContext::State::CANCELED) {
644 fetchContext->state = FetchContext::State::FINISHED;
645 return;
646 } else if (fetchContext->state == FetchContext::State::SENT) {
647 const auto reply = fetchContext->reply;
648 if (reply->state != QNetworkReplyPrivate::Aborted) {
649 int status = fetch->status;
650 QString reasonStr;
651 if (status > 600)
652 reasonStr = QStringLiteral("Operation canceled");
653 else
654 reasonStr = QString::fromUtf8(fetch->statusText);
655 QByteArray statusText(fetch->statusText);
656 QNetworkReply::NetworkError error =
657 reply->statusCodeFromHttp(status, reply->request.url());
658 // Any error body was already streamed in via downloadProgress. Finish
659 // on the reply's own thread, callbacks run on the main thread.
660 QMetaObject::invokeMethod(reply->q_func(),
661 [reply, status, statusText, error, reasonStr]() {
662 reply->setStatusCode(status, statusText);
663 reply->emitReplyError(error, reasonStr);
664 reply->setReplyFinished();
665 }, Qt::QueuedConnection);
666 }
667 reply->m_fetch = nullptr;
668 fetchContext->state = FetchContext::State::FINISHED;
669 emscripten_fetch_close(fetch); // free the fetch struct and its data buffer
670 }
671}
672
673//taken from qhttpthreaddelegate.cpp
674QNetworkReply::NetworkError QNetworkReplyWasmImplPrivate::statusCodeFromHttp(int httpStatusCode, const QUrl &url)
675{
676 QNetworkReply::NetworkError code;
677 // we've got an error
678 switch (httpStatusCode) {
679 case 400: // Bad Request
680 code = QNetworkReply::ProtocolInvalidOperationError;
681 break;
682
683 case 401: // Authorization required
684 code = QNetworkReply::AuthenticationRequiredError;
685 break;
686
687 case 403: // Access denied
688 code = QNetworkReply::ContentAccessDenied;
689 break;
690
691 case 404: // Not Found
692 code = QNetworkReply::ContentNotFoundError;
693 break;
694
695 case 405: // Method Not Allowed
696 code = QNetworkReply::ContentOperationNotPermittedError;
697 break;
698
699 case 407:
700 code = QNetworkReply::ProxyAuthenticationRequiredError;
701 break;
702
703 case 409: // Resource Conflict
704 code = QNetworkReply::ContentConflictError;
705 break;
706
707 case 410: // Content no longer available
708 code = QNetworkReply::ContentGoneError;
709 break;
710
711 case 418: // I'm a teapot
712 code = QNetworkReply::ProtocolInvalidOperationError;
713 break;
714
715 case 500: // Internal Server Error
716 code = QNetworkReply::InternalServerError;
717 break;
718
719 case 501: // Server does not support this functionality
720 code = QNetworkReply::OperationNotImplementedError;
721 break;
722
723 case 503: // Service unavailable
724 code = QNetworkReply::ServiceUnavailableError;
725 break;
726
727 case 65535: //emscripten reply when aborted
728 code = QNetworkReply::OperationCanceledError;
729 break;
730 default:
731 if (httpStatusCode > 500) {
732 // some kind of server error
733 code = QNetworkReply::UnknownServerError;
734 } else if (httpStatusCode >= 400) {
735 // content error we did not handle above
736 code = QNetworkReply::UnknownContentError;
737 } else {
738 qWarning("QNetworkAccess: got HTTP status code %d which is not expected from url: \"%s\"",
739 httpStatusCode, qPrintable(url.toDisplayString()));
740 code = QNetworkReply::ProtocolFailure;
741 }
742 };
743
744 return code;
745}
746
747QT_END_NAMESPACE
748
749#include "moc_qnetworkreplywasmimpl_p.cpp"
void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
void emitReplyError(QNetworkReply::NetworkError errorCode, const QString &)
void setStatusCode(int status, const QByteArray &statusText)
void headersReceived(const QByteArray &buffer)
QNetworkAccessManagerPrivate * managerPrivate
void emitDataReadProgress(qint64 done, qint64 total)
void dataReceived(const QByteArray &buffer)
qint64 size() const override
For open random-access devices, this function returns the size of the device.
virtual qint64 bytesAvailable() const override
Returns the number of bytes that are available for reading.
virtual qint64 readData(char *data, qint64 maxlen) override
virtual void abort() override
Aborts the operation immediately and closes any network connections still open.
virtual bool isSequential() const override
\reimp
virtual void close() override
Closes this device for reading.
Combined button and popup list for selecting options.
constexpr int getArraySize(int factor)
static int parseHeaderName(const QByteArray &headerName)
The FetchContext class ensures the requestData object remains valid while a fetch operation is pendin...
FetchContext(QNetworkReplyWasmImplPrivate *networkReply)
QNetworkReplyWasmImplPrivate * reply