7#include <QtCore/qtimer.h>
8#include <QtCore/qdatetime.h>
9#include <QtCore/qcoreapplication.h>
10#include <QtCore/qfileinfo.h>
11#include <QtCore/qthread.h>
12#include <QtCore/private/qoffsetstringarray_p.h>
13#include <QtCore/private/qtools_p.h>
15#include <private/qnetworkaccessmanager_p.h>
16#include <private/qnetworkfile_p.h>
18#include <emscripten.h>
19#include <emscripten/fetch.h>
30 "access-control-request-headers",
31 "access-control-request-method",
61 , downloadBufferReadPosition(0)
62 , downloadBufferCurrentSize(0)
63 , totalDownloadSize(0)
84QByteArray QNetworkReplyWasmImpl::methodName()
const
137 q->setFinished(
true);
165 qint64 howMuch =
qMin(maxlen, (
d->downloadBuffer.size() -
d->downloadBufferReadPosition));
166 memcpy(
data,
d->downloadBuffer.constData() +
d->downloadBufferReadPosition, howMuch);
167 d->downloadBufferReadPosition += howMuch;
183 bool bufferingDisallowed =
186 if (bufferingDisallowed) {
216 return 2 * factor + 1;
224 emscripten_fetch_attr_t attr;
225 emscripten_fetch_attr_init(&attr);
226 strcpy(attr.requestMethod,
q->methodName().constData());
233 if (headersData.
count() > 0) {
243 if (!trimmedHeaders.isEmpty()) {
244 qWarning() <<
"Qt has trimmed the following forbidden headers from the request:"
247 customHeaders[
i] =
nullptr;
248 attr.requestHeaders = customHeaders;
269 attr.attributes = EMSCRIPTEN_FETCH_LOAD_TO_MEMORY;
275 attr.attributes += EMSCRIPTEN_FETCH_NO_DOWNLOAD;
278 attr.attributes += EMSCRIPTEN_FETCH_APPEND;
283 attr.attributes -= EMSCRIPTEN_FETCH_PERSIST_FILE;
291 attr.timeoutMSecs =
request.transferTimeout();
292 attr.userData =
reinterpret_cast<void *
>(
this);
296 attr.destinationPath = destinationPath.
constData();
316 percentFinished = bytesTotal ? (bytesReceived / bytesTotal) * 100 : 100;
318 emit q->downloadProgress(bytesReceived, bytesTotal);
326 q->setReadBufferSize(bufferSize);
348 auto is = [&](
const char *what) {
354 if (is(
"content-type"))
356 else if (is(
"content-length"))
358 else if (is(
"cookie"))
365 else if (is(
"last-modified"))
370 if (is(
"set-cookie"))
372 else if (is(
"server"))
377 if (is(
"user-agent"))
393 for (
int i = 0;
i < headers.
size();
i++) {
394 if (headers.
at(
i).contains(
':')) {
396 QByteArray headersValue = headers.
at(
i).split(
':').at(1).trimmed();
403 if (headerIndex == -1)
410 emit q->metaDataChanged();
449 if (bytesToBuffer <= 0)
450 bytesToBuffer = 2*1024;
481 reply->setStatusCode(fetch->status, statusText);
482 reply->setReplyFinished();
484 reply->m_fetch =
nullptr;
486 emscripten_fetch_close(fetch);
492 q->setFinished(
true);
493 emit q->readChannelFinished();
508 if (fetch->readyState == 2) {
509 size_t headerLength = emscripten_fetch_get_response_headers_length(fetch);
511 emscripten_fetch_get_response_headers(fetch,
str.
data(),
str.
size());
521 if (fetch->status < 400) {
522 uint64_t bytes = fetch->dataOffset + fetch->numBytes;
523 uint64_t tBytes = fetch->totalBytes;
526 reply->emitDataReadProgress(bytes, tBytes);
537 if (fetch->status > 600)
544 reply->setStatusCode(fetch->status, statusText);
546 reply->setReplyFinished();
548 reply->m_fetch =
nullptr;
550 emscripten_fetch_close(fetch);
558 switch (httpStatusCode) {
611 if (httpStatusCode > 500) {
614 }
else if (httpStatusCode >= 400) {
618 qWarning(
"QNetworkAccess: got HTTP status code %d which is not expected from url: \"%s\"",
629#include "moc_qnetworkreplywasmimpl_p.cpp"
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
qsizetype size() const noexcept
Returns the number of bytes in this byte array.
const char * constData() const noexcept
Returns a pointer to the const data stored in the byte array.
bool isEmpty() const noexcept
Returns true if the byte array has size 0; otherwise returns false.
QByteArray & append(char c)
This is an overloaded member function, provided for convenience. It differs from the above function o...
\inmodule QtCore \reentrant
virtual qint64 size() const
For open random-access devices, this function returns the size of the device.
virtual bool isSequential() const
Returns true if this device is sequential; otherwise returns false.
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
virtual qint64 bytesAvailable() const
Returns the number of bytes that are available for reading.
qint64 read(char *data, qint64 maxlen)
Reads at most maxSize bytes from the device into data, and returns the number of bytes read.
qsizetype size() const noexcept
const_reference at(qsizetype i) const noexcept
qsizetype count() const noexcept
Operation
Indicates the operation this reply is processing.
QNetworkAccessManager::Operation operation
QNetworkReply::NetworkError errorCode
std::shared_ptr< QRingBuffer > outgoingDataBuffer
qint64 downloadBufferCurrentSize
static void setReplyAttributes(quintptr data, int statusCode, const QString &statusReason)
~QNetworkReplyWasmImplPrivate()
void setup(QNetworkAccessManager::Operation op, const QNetworkRequest &request, QIODevice *outgoingData)
static void downloadFailed(emscripten_fetch_t *fetch)
QNetworkReplyWasmImplPrivate()
static void downloadSucceeded(emscripten_fetch_t *fetch)
void emitReplyError(QNetworkReply::NetworkError errorCode, const QString &)
QByteArray downloadBuffer
emscripten_fetch_t * m_fetch
void setStatusCode(int status, const QByteArray &statusText)
void dataReceived(const QByteArray &buffer, int bufferSize)
void _q_bufferOutgoingData()
void headersReceived(const QByteArray &buffer)
static void stateChange(emscripten_fetch_t *fetch)
void emitDataReadProgress(qint64 done, qint64 total)
void _q_bufferOutgoingDataFinished()
static QNetworkReply::NetworkError statusCodeFromHttp(int httpStatusCode, const QUrl &url)
static void downloadProgress(emscripten_fetch_t *fetch)
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 close down any network connections still open.
virtual bool isSequential() const override
QNetworkReplyWasmImpl(QObject *parent=nullptr)
virtual void close() override
Closes this device for reading.
The QNetworkReply class contains the data and headers for a request sent with QNetworkAccessManager.
virtual void close() override
Closes this device for reading.
QNetworkAccessManager::Operation operation() const
Returns the operation that was posted for this reply.
NetworkError
Indicates all possible error conditions found during the processing of the request.
@ ContentOperationNotPermittedError
@ OperationNotImplementedError
@ ServiceUnavailableError
@ ProtocolInvalidOperationError
@ ProxyAuthenticationRequiredError
@ AuthenticationRequiredError
QNetworkRequest request() const
Returns the request that was posted for this reply.
The QNetworkRequest class holds a request to be sent with QNetworkAccessManager.
KnownHeaders
List of known header types that QNetworkRequest parses.
@ UseCredentialsAttribute
@ HttpStatusCodeAttribute
@ CacheSaveControlAttribute
@ CacheLoadControlAttribute
@ DoNotBufferUploadDataAttribute
@ HttpReasonPhraseAttribute
QVariant attribute(Attribute code, const QVariant &defaultValue=QVariant()) const
Returns the attribute associated with the code code.
QVariant header(KnownHeaders header) const
Returns the value of the known network header header if it is present in this request.
QList< QByteArray > rawHeaderList() const
Returns a list of all raw headers that are set in this network request.
QUrl url() const
Returns the URL this network request is referring to.
QByteArray rawHeader(const QByteArray &headerName) const
Returns the raw form of header headerName.
CacheLoadControl
Controls the caching mechanism of QNetworkAccessManager.
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
\threadsafe
\macro QT_RESTRICTED_CAST_FROM_ASCII
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
qsizetype size() const
Returns the number of characters in this string.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QChar * data()
Returns a pointer to the data stored in the QString.
QByteArray toUtf8() const &
QString userInfo(ComponentFormattingOptions options=PrettyDecoded) const
Returns the user info of the URL, or an empty string if the user info is undefined.
QString fileName(ComponentFormattingOptions options=FullyDecoded) const
QString userName(ComponentFormattingOptions options=FullyDecoded) const
Returns the user name of the URL if it is defined; otherwise an empty string is returned.
QString password(ComponentFormattingOptions=FullyDecoded) const
Returns the password of the URL if it is defined; otherwise an empty string is returned.
QString toString(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
bool isValid() const
Returns true if the storage type of this variant is not QMetaType::UnknownType; otherwise returns fal...
int toInt(bool *ok=nullptr) const
Returns the variant as an int if the variant has userType() \l QMetaType::Int, \l QMetaType::Bool,...
bool toBool() const
Returns the variant as a bool if the variant has userType() Bool.
Combined button and popup list for selecting options.
constexpr char toAsciiLower(char ch) noexcept
constexpr Initialization Uninitialized
static int arrayLength(const QString &rawType)
int qstrnicmp(const char *str1, qsizetype len1, const char *str2, qsizetype len2)
static QString header(const QString &name)
constexpr const T & qMin(const T &a, const T &b)
constexpr int getArraySize(int factor)
static int parseHeaderName(const QByteArray &headerName)
static QByteArray headerName(QNetworkRequest::KnownHeaders header)
constexpr auto qOffsetStringArray(const char(&...strings)[Nx]) noexcept
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLdouble GLdouble GLdouble GLdouble q
#define qPrintable(string)
#define QStringLiteral(str)
QUrl url("example.com")
[constructor-url-reference]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent