Mercurial > minori
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 229:adc20fa321c1 | 230:2f5a9247e501 |
|---|---|
| 1 #ifndef __core__http_h | 1 #ifndef __core__http_h |
| 2 #define __core__http_h | 2 #define __core__http_h |
| 3 | 3 |
| 4 #include <QByteArray> | 4 #include <QByteArray> |
| 5 #include <QThread> | |
| 5 #include <string> | 6 #include <string> |
| 6 #include <vector> | 7 #include <vector> |
| 7 | 8 |
| 8 namespace HTTP { | 9 namespace HTTP { |
| 9 | 10 |
| 10 QByteArray Get(const std::string& url, const std::vector<std::string>& headers = {}); | 11 QByteArray Get(const std::string& url, const std::vector<std::string>& headers = {}); |
| 11 QByteArray Post(const std::string& url, const std::string& data, const std::vector<std::string>& headers = {}); | 12 QByteArray Post(const std::string& url, const std::string& data, const std::vector<std::string>& headers = {}); |
| 12 | 13 |
| 14 class GetThread : public QThread { | |
| 15 Q_OBJECT | |
| 16 | |
| 17 public: | |
| 18 GetThread(const std::string& u, const std::vector<std::string>& h = {}) { | |
| 19 url = u; | |
| 20 headers = h; | |
| 21 } | |
| 22 | |
| 23 signals: | |
| 24 void ReceivedData(const QByteArray& ba); | |
| 25 | |
| 26 protected: | |
| 27 void run() override { | |
| 28 emit ReceivedData(Get(url, headers)); | |
| 29 } | |
| 30 | |
| 31 std::string url; | |
| 32 std::vector<std::string> headers; | |
| 33 }; | |
| 34 | |
| 35 class PostThread : public QThread { | |
| 36 Q_OBJECT | |
| 37 | |
| 38 public: | |
| 39 PostThread(const std::string& u, const std::string& d, const std::vector<std::string>& h = {}) { | |
| 40 url = u; | |
| 41 data = d; | |
| 42 headers = h; | |
| 43 } | |
| 44 | |
| 45 signals: | |
| 46 void ReceivedData(const QByteArray& ba); | |
| 47 | |
| 48 protected: | |
| 49 void run() override { | |
| 50 emit ReceivedData(Post(url, data, headers)); | |
| 51 } | |
| 52 | |
| 53 std::string url; | |
| 54 std::string data; | |
| 55 std::vector<std::string> headers; | |
| 56 }; | |
| 57 | |
| 13 } // namespace HTTP | 58 } // namespace HTTP |
| 14 | 59 |
| 15 #endif // __core__http_h | 60 #endif // __core__http_h |
