annotate include/core/http.h @ 75:d3e9310598b1

*: refactor some stuff text: "TextParagraph"s are now called sections, because that's the actual word for it :P text: new classes: Line and OneLineSection, solves many problems with paragraphs that are only one line long (ex. going out of bounds) http: reworked http stuff to allow threaded get requests, also moved it to its own file to (hopefully) remove clutter eventually I'll make a threaded post request method and use that in the "basic" function
author Paper <mrpapersonic@gmail.com>
date Wed, 04 Oct 2023 01:42:30 -0400
parents
children 3364fadc8a36
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
75
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
1 #ifndef __core__http_h
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
2 #define __core__http_h
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
3
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
4 #include <string>
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
5 #include <vector>
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
6 #include <QThread>
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
7
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
8 class QObject;
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
9
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
10 namespace HTTP {
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
11
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
12 class HttpGetThread : public QThread {
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
13 Q_OBJECT
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
14
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
15 public:
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
16 HttpGetThread(std::string url, std::vector<std::string> headers = {}, QObject* parent = nullptr);
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
17
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
18 private:
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
19 static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userdata);
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
20 void run() override;
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
21 std::string _url;
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
22 std::vector<std::string> _headers;
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
23
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
24 signals:
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
25 void resultReady(const QByteArray& arr);
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
26 };
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
27
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
28 /* Performs a basic (blocking) post request */
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
29 std::string PerformBasicPostRequest(std::string url, std::string data, std::vector<std::string> headers = {});
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
30
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
31 }
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
32
d3e9310598b1 *: refactor some stuff
Paper <mrpapersonic@gmail.com>
parents:
diff changeset
33 #endif // __core__http_h