Mercurial > minori
annotate include/core/http.h @ 236:4d461ef7d424
HUGE UPDATE: convert build system to autotools
why? because cmake sucks :)
author | Paper <mrpapersonic@gmail.com> |
---|---|
date | Fri, 19 Jan 2024 00:24:02 -0500 |
parents | 2f5a9247e501 |
children | 862d0d8619f6 |
rev | line source |
---|---|
75 | 1 #ifndef __core__http_h |
2 #define __core__http_h | |
3 | |
77 | 4 #include <QByteArray> |
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
5 #include <QThread> |
75 | 6 #include <string> |
7 #include <vector> | |
8 | |
9 namespace HTTP { | |
10 | |
100
f5940a575d83
track/constants: add many more video formats
Paper <mrpapersonic@gmail.com>
parents:
77
diff
changeset
|
11 QByteArray Get(const std::string& url, const std::vector<std::string>& headers = {}); |
f5940a575d83
track/constants: add many more video formats
Paper <mrpapersonic@gmail.com>
parents:
77
diff
changeset
|
12 QByteArray Post(const std::string& url, const std::string& data, const std::vector<std::string>& headers = {}); |
75 | 13 |
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
14 class GetThread : public QThread { |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
15 Q_OBJECT |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
16 |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
17 public: |
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
18 GetThread(const std::string& u, const std::vector<std::string>& h = {}, QObject* parent = nullptr) : QThread(parent) { |
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
19 url = u; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
20 headers = h; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
21 } |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
22 |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
23 signals: |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
24 void ReceivedData(const QByteArray& ba); |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
25 |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
26 protected: |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
27 void run() override { |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
28 emit ReceivedData(Get(url, headers)); |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
29 } |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
30 |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
31 std::string url; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
32 std::vector<std::string> headers; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
33 }; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
34 |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
35 class PostThread : public QThread { |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
36 Q_OBJECT |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
37 |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
38 public: |
236
4d461ef7d424
HUGE UPDATE: convert build system to autotools
Paper <mrpapersonic@gmail.com>
parents:
230
diff
changeset
|
39 PostThread(const std::string& u, const std::string& d, const std::vector<std::string>& h = {}, QObject* parent = nullptr) : QThread(parent) { |
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
40 url = u; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
41 data = d; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
42 headers = h; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
43 } |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
44 |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
45 signals: |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
46 void ReceivedData(const QByteArray& ba); |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
47 |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
48 protected: |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
49 void run() override { |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
50 emit ReceivedData(Post(url, data, headers)); |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
51 } |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
52 |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
53 std::string url; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
54 std::string data; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
55 std::vector<std::string> headers; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
56 }; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
57 |
76 | 58 } // namespace HTTP |
75 | 59 |
60 #endif // __core__http_h |