Mercurial > minori
annotate include/core/http.h @ 261:3ec7804abf17
include: make header guards more sane
The C++ standard[1] says:
Each identifier that contains a double underscore __ or
begins with an underscore followed by an uppercase letter
is reserved to the implementation for any use.
[1]: https://timsong-cpp.github.io/cppwp/n4659/lex.name#3.1
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Wed, 03 Apr 2024 20:04:28 -0400 |
parents | 862d0d8619f6 |
children | 9a88e1725fd2 |
rev | line source |
---|---|
261
3ec7804abf17
include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
1 #ifndef MINORI_CORE_HTTP_H_ |
3ec7804abf17
include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
2 #define MINORI_CORE_HTTP_H_ |
75 | 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: |
258 | 18 GetThread(const std::string& u, const std::vector<std::string>& h = {}, QObject* parent = nullptr) |
19 : QThread(parent) { | |
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
20 url = u; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
21 headers = h; |
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 |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
24 signals: |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
25 void ReceivedData(const QByteArray& ba); |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
26 |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
27 protected: |
258 | 28 void run() override { emit ReceivedData(Get(url, headers)); } |
230
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 std::string url; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
31 std::vector<std::string> headers; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
32 }; |
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 class PostThread : public QThread { |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
35 Q_OBJECT |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
36 |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
37 public: |
258 | 38 PostThread(const std::string& u, const std::string& d, const std::vector<std::string>& h = {}, |
39 QObject* parent = nullptr) | |
40 : QThread(parent) { | |
230
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
41 url = u; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
42 data = d; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
43 headers = h; |
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 |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
46 signals: |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
47 void ReceivedData(const QByteArray& ba); |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
48 |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
49 protected: |
258 | 50 void run() override { emit ReceivedData(Post(url, data, headers)); } |
230
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 std::string url; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
53 std::string data; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
54 std::vector<std::string> headers; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
55 }; |
2f5a9247e501
torrents: implement download button
Paper <paper@paper.us.eu.org>
parents:
100
diff
changeset
|
56 |
76 | 57 } // namespace HTTP |
75 | 58 |
261
3ec7804abf17
include: make header guards more sane
Paper <paper@paper.us.eu.org>
parents:
258
diff
changeset
|
59 #endif // MINORI_CORE_HTTP_H_ |