Mercurial > minori
diff include/core/http.h @ 230:2f5a9247e501
torrents: implement download button
erg
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Sat, 13 Jan 2024 09:42:02 -0500 |
parents | f5940a575d83 |
children | 4d461ef7d424 |
line wrap: on
line diff
--- a/include/core/http.h Wed Jan 10 21:23:57 2024 -0500 +++ b/include/core/http.h Sat Jan 13 09:42:02 2024 -0500 @@ -2,6 +2,7 @@ #define __core__http_h #include <QByteArray> +#include <QThread> #include <string> #include <vector> @@ -10,6 +11,50 @@ QByteArray Get(const std::string& url, const std::vector<std::string>& headers = {}); QByteArray Post(const std::string& url, const std::string& data, const std::vector<std::string>& headers = {}); +class GetThread : public QThread { + Q_OBJECT + +public: + GetThread(const std::string& u, const std::vector<std::string>& h = {}) { + url = u; + headers = h; + } + +signals: + void ReceivedData(const QByteArray& ba); + +protected: + void run() override { + emit ReceivedData(Get(url, headers)); + } + + std::string url; + std::vector<std::string> headers; +}; + +class PostThread : public QThread { + Q_OBJECT + +public: + PostThread(const std::string& u, const std::string& d, const std::vector<std::string>& h = {}) { + url = u; + data = d; + headers = h; + } + +signals: + void ReceivedData(const QByteArray& ba); + +protected: + void run() override { + emit ReceivedData(Post(url, data, headers)); + } + + std::string url; + std::string data; + std::vector<std::string> headers; +}; + } // namespace HTTP #endif // __core__http_h