annotate include/core/http.h @ 370:ea3a74ed2ef9

*: hm, last commit wasn't quite finished?
author Paper <paper@tflc.us>
date Fri, 25 Jul 2025 10:22:04 -0400
parents 47c9f8502269
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
1 #ifndef MINORI_CORE_HTTP_H_
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
2 #define MINORI_CORE_HTTP_H_
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
3
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
4 #include <QByteArray>
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
5 #include <QThread>
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
6
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 317
diff changeset
7 #include <mutex>
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
8 #include <string>
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
9 #include <vector>
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
10
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
11 namespace HTTP {
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
12
317
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
13 /* calls libcurl to encode/decode */
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 317
diff changeset
14 std::string UrlEncode(const std::string &data);
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 317
diff changeset
15 std::string UrlDecode(const std::string &data);
317
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
16
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 317
diff changeset
17 std::string EncodeParamsList(std::string base, const std::map<std::string, std::string> &params);
317
b1f4d1867ab1 services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents: 301
diff changeset
18
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
19 enum class Type {
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
20 Get,
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
21 Post
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
22 };
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
23
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 317
diff changeset
24 QByteArray Request(const std::string &url, const std::vector<std::string> &headers = {}, const std::string &data = "",
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 317
diff changeset
25 Type type = Type::Get);
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
26
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
27 class RequestThread final : public QThread {
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
28 Q_OBJECT
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
29
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
30 public:
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 317
diff changeset
31 RequestThread(Type type = Type::Get, QObject *parent = nullptr);
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 317
diff changeset
32 RequestThread(const std::string &url, const std::vector<std::string> &headers = {}, const std::string &data = "",
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 317
diff changeset
33 Type type = Type::Get, QObject *parent = nullptr);
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
34 ~RequestThread();
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
35
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 317
diff changeset
36 void SetUrl(const std::string &url);
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 317
diff changeset
37 void SetHeaders(const std::vector<std::string> &headers);
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 317
diff changeset
38 void SetData(const std::string &data);
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
39 void SetType(Type type);
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
40
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
41 void Stop();
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
42
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
43 signals:
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 317
diff changeset
44 void ReceivedData(const QByteArray &ba);
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
45
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
46 protected:
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
47 void run() override;
369
47c9f8502269 *: clang-format all the things
Paper <paper@tflc.us>
parents: 317
diff changeset
48 static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userdata);
301
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
49
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
50 std::string url_;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
51 std::string data_;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
52 std::vector<std::string> headers_;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
53 Type type_;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
54
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
55 /* these are passed to the write callback */
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
56 QByteArray array_;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
57 bool cancelled_ = false;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
58
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
59 /* don't fuck this up */
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
60 std::mutex callback_data_mutex_;
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
61 };
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
62
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
63 } // namespace HTTP
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
64
b1f625b0227c *: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents: 291
diff changeset
65 #endif // MINORI_CORE_HTTP_H_