Mercurial > minori
comparison include/core/http.h @ 369:47c9f8502269
*: clang-format all the things
I've edited the formatting a bit. Now pointer asterisks (and reference
ampersands) are on the variable instead of the type, as well as having
newlines for function braces (but nothing else)
author | Paper <paper@tflc.us> |
---|---|
date | Fri, 25 Jul 2025 10:16:02 -0400 |
parents | b1f4d1867ab1 |
children |
comparison
equal
deleted
inserted
replaced
368:6d37a998cf91 | 369:47c9f8502269 |
---|---|
2 #define MINORI_CORE_HTTP_H_ | 2 #define MINORI_CORE_HTTP_H_ |
3 | 3 |
4 #include <QByteArray> | 4 #include <QByteArray> |
5 #include <QThread> | 5 #include <QThread> |
6 | 6 |
7 #include <mutex> | |
7 #include <string> | 8 #include <string> |
8 #include <vector> | 9 #include <vector> |
9 #include <mutex> | |
10 | 10 |
11 namespace HTTP { | 11 namespace HTTP { |
12 | 12 |
13 /* calls libcurl to encode/decode */ | 13 /* calls libcurl to encode/decode */ |
14 std::string UrlEncode(const std::string& data); | 14 std::string UrlEncode(const std::string &data); |
15 std::string UrlDecode(const std::string& data); | 15 std::string UrlDecode(const std::string &data); |
16 | 16 |
17 std::string EncodeParamsList(std::string base, const std::map<std::string, std::string>& params); | 17 std::string EncodeParamsList(std::string base, const std::map<std::string, std::string> ¶ms); |
18 | 18 |
19 enum class Type { | 19 enum class Type { |
20 Get, | 20 Get, |
21 Post | 21 Post |
22 }; | 22 }; |
23 | 23 |
24 QByteArray Request(const std::string& url, const std::vector<std::string>& headers = {}, const std::string& data = "", Type type = Type::Get); | 24 QByteArray Request(const std::string &url, const std::vector<std::string> &headers = {}, const std::string &data = "", |
25 Type type = Type::Get); | |
25 | 26 |
26 class RequestThread final : public QThread { | 27 class RequestThread final : public QThread { |
27 Q_OBJECT | 28 Q_OBJECT |
28 | 29 |
29 public: | 30 public: |
30 RequestThread(Type type = Type::Get, QObject* parent = nullptr); | 31 RequestThread(Type type = Type::Get, QObject *parent = nullptr); |
31 RequestThread(const std::string& url, const std::vector<std::string>& headers = {}, | 32 RequestThread(const std::string &url, const std::vector<std::string> &headers = {}, const std::string &data = "", |
32 const std::string& data = "", Type type = Type::Get, QObject* parent = nullptr); | 33 Type type = Type::Get, QObject *parent = nullptr); |
33 ~RequestThread(); | 34 ~RequestThread(); |
34 | 35 |
35 void SetUrl(const std::string& url); | 36 void SetUrl(const std::string &url); |
36 void SetHeaders(const std::vector<std::string>& headers); | 37 void SetHeaders(const std::vector<std::string> &headers); |
37 void SetData(const std::string& data); | 38 void SetData(const std::string &data); |
38 void SetType(Type type); | 39 void SetType(Type type); |
39 | 40 |
40 void Stop(); | 41 void Stop(); |
41 | 42 |
42 signals: | 43 signals: |
43 void ReceivedData(const QByteArray& ba); | 44 void ReceivedData(const QByteArray &ba); |
44 | 45 |
45 protected: | 46 protected: |
46 void run() override; | 47 void run() override; |
47 static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userdata); | 48 static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userdata); |
48 | 49 |
49 std::string url_; | 50 std::string url_; |
50 std::string data_; | 51 std::string data_; |
51 std::vector<std::string> headers_; | 52 std::vector<std::string> headers_; |
52 Type type_; | 53 Type type_; |