Files
chatterino2/src/common/NetworkPrivate.hpp
nerix ce47d27d41 Refactor/Cleanup NetworkRequest and Related Code (#4633)
Cleanup unused code (Twitch v5)
Add json methods that simplify sending JSON. This also sets the Accepts header, since here, when JSON is sent, only JSON is accepted as a response (this is only done in Helix).
Clarify helix request creations
Cleaned some clang-tidy suggestions in Network{Request,Private}
2023-05-16 17:28:20 +02:00

74 lines
1.4 KiB
C++

#pragma once
#include "common/NetworkCommon.hpp"
#include "util/QObjectRef.hpp"
#include <QHttpMultiPart>
#include <QNetworkRequest>
#include <QTimer>
#include <functional>
#include <memory>
class QNetworkReply;
namespace chatterino {
class NetworkResult;
class NetworkRequester : public QObject
{
Q_OBJECT
signals:
void requestUrl();
};
class NetworkWorker : public QObject
{
Q_OBJECT
signals:
void doneUrl();
};
struct NetworkData {
NetworkData();
~NetworkData();
QNetworkRequest request_;
bool hasCaller_{};
QObjectRef<QObject> caller_;
bool cache_{};
bool executeConcurrently_{};
NetworkReplyCreatedCallback onReplyCreated_;
NetworkErrorCallback onError_;
NetworkSuccessCallback onSuccess_;
NetworkFinallyCallback finally_;
NetworkRequestType requestType_ = NetworkRequestType::Get;
QByteArray payload_;
// lifetime secured by lifetimeManager_
QHttpMultiPart *multiPartPayload_{};
// Timer that tracks the timeout
// By default, there's no explicit timeout for the request
// to enable the timer, the "setTimeout" function needs to be called before
// execute is called
bool hasTimeout_{};
int timeoutMS_{};
QTimer *timer_ = nullptr;
QObject *lifetimeManager_;
QString getHash();
private:
QString hash_;
};
void load(std::shared_ptr<NetworkData> &&data);
} // namespace chatterino