Skip to content

Commit

Permalink
wasm: enable httpmultipart
Browse files Browse the repository at this point in the history
This allows for multipart requests.

Change-Id: I1206d160cfd9150a9627c36ed60ea4cbb58e95aa
Reviewed-by: Mårten Nordheim <[email protected]>
  • Loading branch information
lpotter committed Sep 4, 2020
1 parent 225cc60 commit 6b171dc
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 6 deletions.
11 changes: 11 additions & 0 deletions src/network/access/access.pri
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,14 @@ qtConfig(http) {
QMAKE_USE_PRIVATE += zstd
}
}

wasm: {
SOURCES += \
access/qhttpmultipart.cpp \
access/qhttpnetworkheader.cpp

HEADERS += \
access/qhttpmultipart.h \
access/qhttpmultipart_p.h \
access/qhttpnetworkheader_p.h
}
2 changes: 2 additions & 0 deletions src/network/access/qhttpmultipart.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
#include <QtCore/QIODevice>
#include <QtNetwork/QNetworkRequest>

#ifndef Q_OS_WASM
QT_REQUIRE_CONFIG(http);
#endif

QT_BEGIN_NAMESPACE

Expand Down
2 changes: 2 additions & 0 deletions src/network/access/qhttpmultipart_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
#include "qnetworkrequest_p.h" // for deriving QHttpPartPrivate from QNetworkHeadersPrivate
#include "private/qobject_p.h"

#ifndef Q_OS_WASM
QT_REQUIRE_CONFIG(http);
#endif

QT_BEGIN_NAMESPACE

Expand Down
2 changes: 2 additions & 0 deletions src/network/access/qhttpnetworkconnection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair)
QByteArray value;
// check if Content-Length is provided
QNonContiguousByteDevice* uploadByteDevice = request.uploadByteDevice();
#ifndef Q_OS_WASM
if (uploadByteDevice) {
const qint64 contentLength = request.contentLength();
const qint64 uploadDeviceSize = uploadByteDevice->size();
Expand All @@ -274,6 +275,7 @@ void QHttpNetworkConnectionPrivate::prepareRequest(HttpMessagePair &messagePair)
qFatal("QHttpNetworkConnectionPrivate: Neither content-length nor upload device size were given");
}
}
#endif
// set the Connection/Proxy-Connection: Keep-Alive headers
#ifndef QT_NO_NETWORKPROXY
if (networkProxy.type() == QNetworkProxy::HttpCachingProxy) {
Expand Down
2 changes: 2 additions & 0 deletions src/network/access/qhttpnetworkheader_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
#include <qshareddata.h>
#include <qurl.h>

#ifndef Q_OS_WASM
QT_REQUIRE_CONFIG(http);
#endif

QT_BEGIN_NAMESPACE

Expand Down
2 changes: 2 additions & 0 deletions src/network/access/qhttpnetworkrequest_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@
#include <QtNetwork/qnetworkrequest.h>
#include <qmetatype.h>

#ifndef Q_OS_WASM
QT_REQUIRE_CONFIG(http);
#endif

QT_BEGIN_NAMESPACE

Expand Down
13 changes: 9 additions & 4 deletions src/network/access/qnetworkaccessmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
#endif
#ifdef Q_OS_WASM
#include "qnetworkreplywasmimpl_p.h"
#include "qhttpmultipart.h"
#include "qhttpmultipart_p.h"
#endif

#include "qnetconmonitor_p.h"
Expand Down Expand Up @@ -823,7 +825,7 @@ QNetworkReply *QNetworkAccessManager::post(const QNetworkRequest &request, const
return reply;
}

#if QT_CONFIG(http)
#if QT_CONFIG(http) || defined(Q_OS_WASM)
/*!
\since 4.8
Expand Down Expand Up @@ -1090,7 +1092,7 @@ QNetworkReply *QNetworkAccessManager::sendCustomRequest(const QNetworkRequest &r
return reply;
}

#if QT_CONFIG(http)
#if QT_CONFIG(http) || defined(Q_OS_WASM)
/*!
\since 5.8
Expand Down Expand Up @@ -1189,13 +1191,14 @@ QNetworkReply *QNetworkAccessManager::createRequest(QNetworkAccessManager::Opera
}
#endif
QNetworkRequest request = req;
#ifndef Q_OS_WASM // Content-length header is not allowed to be set by user in wasm
if (!request.header(QNetworkRequest::ContentLengthHeader).isValid() &&
outgoingData && !outgoingData->isSequential()) {
// request has no Content-Length
// but the data that is outgoing is random-access
request.setHeader(QNetworkRequest::ContentLengthHeader, outgoingData->size());
}

#endif
if (static_cast<QNetworkRequest::LoadControl>
(request.attribute(QNetworkRequest::CookieLoadControlAttribute,
QNetworkRequest::Automatic).toInt()) == QNetworkRequest::Automatic) {
Expand Down Expand Up @@ -1644,7 +1647,9 @@ void QNetworkAccessManagerPrivate::destroyThread()
}
}

#if QT_CONFIG(http)

#if QT_CONFIG(http) || defined(Q_OS_WASM)

QNetworkRequest QNetworkAccessManagerPrivate::prepareMultipart(const QNetworkRequest &request, QHttpMultiPart *multiPart)
{
// copy the request, we probably need to add some headers
Expand Down
2 changes: 1 addition & 1 deletion src/network/access/qnetworkaccessmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class Q_NETWORK_EXPORT QNetworkAccessManager: public QObject
QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QIODevice *data = nullptr);
QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, const QByteArray &data);

#if QT_CONFIG(http)
#if QT_CONFIG(http) || defined(Q_OS_WASM)
QNetworkReply *post(const QNetworkRequest &request, QHttpMultiPart *multiPart);
QNetworkReply *put(const QNetworkRequest &request, QHttpMultiPart *multiPart);
QNetworkReply *sendCustomRequest(const QNetworkRequest &request, const QByteArray &verb, QHttpMultiPart *multiPart);
Expand Down
2 changes: 1 addition & 1 deletion src/network/access/qnetworkaccessmanager_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class QNetworkAccessManagerPrivate: public QObjectPrivate
QNetworkAccessBackend *findBackend(QNetworkAccessManager::Operation op, const QNetworkRequest &request);
QStringList backendSupportedSchemes() const;

#if QT_CONFIG(http)
#if QT_CONFIG(http) || defined(Q_OS_WASM)
QNetworkRequest prepareMultipart(const QNetworkRequest &request, QHttpMultiPart *multiPart);
#endif

Expand Down

0 comments on commit 6b171dc

Please sign in to comment.