mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-13 19:49:51 +01:00
added multipart support to NetworkRequest
This commit is contained in:
parent
ce53653ecd
commit
986694e4bc
|
@ -17,6 +17,7 @@ namespace chatterino {
|
||||||
|
|
||||||
NetworkData::NetworkData()
|
NetworkData::NetworkData()
|
||||||
: timer_(new QTimer())
|
: timer_(new QTimer())
|
||||||
|
, lifetimeManager_(new QObject)
|
||||||
{
|
{
|
||||||
timer_->setSingleShot(true);
|
timer_->setSingleShot(true);
|
||||||
|
|
||||||
|
@ -26,6 +27,7 @@ NetworkData::NetworkData()
|
||||||
NetworkData::~NetworkData()
|
NetworkData::~NetworkData()
|
||||||
{
|
{
|
||||||
this->timer_->deleteLater();
|
this->timer_->deleteLater();
|
||||||
|
this->lifetimeManager_->deleteLater();
|
||||||
|
|
||||||
DebugCount::decrease("NetworkData");
|
DebugCount::decrease("NetworkData");
|
||||||
}
|
}
|
||||||
|
@ -104,8 +106,18 @@ void loadUncached(const std::shared_ptr<NetworkData> &data)
|
||||||
data->request_);
|
data->request_);
|
||||||
|
|
||||||
case NetworkRequestType::Post:
|
case NetworkRequestType::Post:
|
||||||
return NetworkManager::accessManager.post(data->request_,
|
if (data->multiPartPayload_)
|
||||||
data->payload_);
|
{
|
||||||
|
assert(data->payload_.isNull());
|
||||||
|
|
||||||
|
return NetworkManager::accessManager.post(
|
||||||
|
data->request_, data->multiPartPayload_);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NetworkManager::accessManager.post(
|
||||||
|
data->request_, data->payload_);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}();
|
}();
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
#include "common/NetworkCommon.hpp"
|
#include "common/NetworkCommon.hpp"
|
||||||
#include "util/QObjectRef.hpp"
|
#include "util/QObjectRef.hpp"
|
||||||
|
|
||||||
|
#include <QHttpMultiPart>
|
||||||
#include <QNetworkRequest>
|
#include <QNetworkRequest>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
|
@ -45,6 +46,8 @@ struct NetworkData {
|
||||||
NetworkRequestType requestType_ = NetworkRequestType::Get;
|
NetworkRequestType requestType_ = NetworkRequestType::Get;
|
||||||
|
|
||||||
QByteArray payload_;
|
QByteArray payload_;
|
||||||
|
// lifetime secured by lifetimeManager_
|
||||||
|
QHttpMultiPart *multiPartPayload_{};
|
||||||
|
|
||||||
// Timer that tracks the timeout
|
// Timer that tracks the timeout
|
||||||
// By default, there's no explicit timeout for the request
|
// By default, there's no explicit timeout for the request
|
||||||
|
@ -52,6 +55,7 @@ struct NetworkData {
|
||||||
// execute is called
|
// execute is called
|
||||||
bool hasTimeout_{};
|
bool hasTimeout_{};
|
||||||
QTimer *timer_;
|
QTimer *timer_;
|
||||||
|
QObject *lifetimeManager_;
|
||||||
|
|
||||||
QString getHash();
|
QString getHash();
|
||||||
|
|
||||||
|
|
|
@ -127,6 +127,13 @@ NetworkRequest NetworkRequest::authorizeTwitchV5(const QString &clientID,
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NetworkRequest NetworkRequest::multiPart(QHttpMultiPart *payload) &&
|
||||||
|
{
|
||||||
|
payload->setParent(this->data->lifetimeManager_);
|
||||||
|
this->data->multiPartPayload_ = payload;
|
||||||
|
return std::move(*this);
|
||||||
|
}
|
||||||
|
|
||||||
NetworkRequest NetworkRequest::payload(const QByteArray &payload) &&
|
NetworkRequest NetworkRequest::payload(const QByteArray &payload) &&
|
||||||
{
|
{
|
||||||
this->data->payload_ = payload;
|
this->data->payload_ = payload;
|
||||||
|
|
|
@ -56,6 +56,7 @@ public:
|
||||||
NetworkRequest concurrent() &&;
|
NetworkRequest concurrent() &&;
|
||||||
NetworkRequest authorizeTwitchV5(const QString &clientID,
|
NetworkRequest authorizeTwitchV5(const QString &clientID,
|
||||||
const QString &oauthToken = QString()) &&;
|
const QString &oauthToken = QString()) &&;
|
||||||
|
NetworkRequest multiPart(QHttpMultiPart *payload) &&;
|
||||||
|
|
||||||
void execute();
|
void execute();
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue