Mercurial > minori
annotate include/core/http.h @ 327:b5d6c27c308f
anime: refactor Anime::SeriesSeason to Season class
ToLocalString has also been altered to take in both season
and year because lots of locales actually treat formatting
seasons differently! most notably is Russian which adds a
suffix at the end to notate seasons(??)
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Thu, 13 Jun 2024 01:49:18 -0400 |
parents | b1f4d1867ab1 |
children |
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 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
7 #include <string> |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
8 #include <vector> |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
9 #include <mutex> |
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 */ |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
301
diff
changeset
|
14 std::string UrlEncode(const std::string& data); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
301
diff
changeset
|
15 std::string UrlDecode(const std::string& data); |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
301
diff
changeset
|
16 |
b1f4d1867ab1
services: VERY initial Kitsu support
Paper <paper@paper.us.eu.org>
parents:
301
diff
changeset
|
17 std::string EncodeParamsList(std::string base, const std::map<std::string, std::string>& params); |
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 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
24 QByteArray Request(const std::string& url, const std::vector<std::string>& headers = {}, const std::string& data = "", Type type = Type::Get); |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
25 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
26 class RequestThread final : public QThread { |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
27 Q_OBJECT |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
28 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
29 public: |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
30 RequestThread(Type type = Type::Get, QObject* parent = nullptr); |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
31 RequestThread(const std::string& url, const std::vector<std::string>& headers = {}, |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
32 const std::string& data = "", Type type = Type::Get, QObject* parent = nullptr); |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
33 ~RequestThread(); |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
34 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
35 void SetUrl(const std::string& url); |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
36 void SetHeaders(const std::vector<std::string>& headers); |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
37 void SetData(const std::string& data); |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
38 void SetType(Type type); |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
39 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
40 void Stop(); |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
41 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
42 signals: |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
43 void ReceivedData(const QByteArray& ba); |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
44 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
45 protected: |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
46 void run() override; |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
47 static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userdata); |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
48 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
49 std::string url_; |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
50 std::string data_; |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
51 std::vector<std::string> headers_; |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
52 Type type_; |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
53 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
54 /* these are passed to the write callback */ |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
55 QByteArray array_; |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
56 bool cancelled_ = false; |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
57 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
58 /* don't fuck this up */ |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
59 std::mutex callback_data_mutex_; |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
60 }; |
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 } // namespace HTTP |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
63 |
b1f625b0227c
*: convert all files CRLF -> LF
Paper <paper@paper.us.eu.org>
parents:
291
diff
changeset
|
64 #endif // MINORI_CORE_HTTP_H_ |