wasm: enable httpmultipart

This allows for multipart requests.

Change-Id: I1206d160cfd9150a9627c36ed60ea4cbb58e95aa
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
bb10
Lorn Potter 2019-05-10 19:16:22 +10:00
parent 225cc60954
commit 6b171dc6c0
9 changed files with 32 additions and 6 deletions

View File

@ -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
}

View File

@ -46,7 +46,9 @@
#include <QtCore/QIODevice>
#include <QtNetwork/QNetworkRequest>
#ifndef Q_OS_WASM
QT_REQUIRE_CONFIG(http);
#endif
QT_BEGIN_NAMESPACE

View File

@ -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

View File

@ -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();
@ -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) {

View File

@ -56,7 +56,9 @@
#include <qshareddata.h>
#include <qurl.h>
#ifndef Q_OS_WASM
QT_REQUIRE_CONFIG(http);
#endif
QT_BEGIN_NAMESPACE

View File

@ -56,7 +56,9 @@
#include <QtNetwork/qnetworkrequest.h>
#include <qmetatype.h>
#ifndef Q_OS_WASM
QT_REQUIRE_CONFIG(http);
#endif
QT_BEGIN_NAMESPACE

View File

@ -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"
@ -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
@ -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
@ -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) {
@ -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

View File

@ -124,7 +124,7 @@ public:
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);

View File

@ -126,7 +126,7 @@ public:
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