Mercurial > minori
view include/core/http.h @ 337:a7d4e5107531
dep/animone: REFACTOR ALL THE THINGS
1: animone now has its own syntax divergent from anisthesia,
making different platforms actually have their own sections
2: process names in animone are now called `comm' (this will
probably break things). this is what its called in bsd/linux
so I'm just going to use it everywhere
3: the X11 code now checks for the existence of a UTF-8 window title
and passes it if available
4: ANYTHING THATS NOT LINUX IS 100% UNTESTED AND CAN AND WILL BREAK!
I still actually need to test the bsd code. to be honest I'm probably
going to move all of the bsds into separate files because they're
all essentially different operating systems at this point
author | Paper <paper@paper.us.eu.org> |
---|---|
date | Wed, 19 Jun 2024 12:51:15 -0400 |
parents | b1f4d1867ab1 |
children |
line wrap: on
line source
#ifndef MINORI_CORE_HTTP_H_ #define MINORI_CORE_HTTP_H_ #include <QByteArray> #include <QThread> #include <string> #include <vector> #include <mutex> namespace HTTP { /* calls libcurl to encode/decode */ std::string UrlEncode(const std::string& data); std::string UrlDecode(const std::string& data); std::string EncodeParamsList(std::string base, const std::map<std::string, std::string>& params); enum class Type { Get, Post }; QByteArray Request(const std::string& url, const std::vector<std::string>& headers = {}, const std::string& data = "", Type type = Type::Get); class RequestThread final : public QThread { Q_OBJECT public: RequestThread(Type type = Type::Get, QObject* parent = nullptr); RequestThread(const std::string& url, const std::vector<std::string>& headers = {}, const std::string& data = "", Type type = Type::Get, QObject* parent = nullptr); ~RequestThread(); void SetUrl(const std::string& url); void SetHeaders(const std::vector<std::string>& headers); void SetData(const std::string& data); void SetType(Type type); void Stop(); signals: void ReceivedData(const QByteArray& ba); protected: void run() override; static size_t WriteCallback(void* contents, size_t size, size_t nmemb, void* userdata); std::string url_; std::string data_; std::vector<std::string> headers_; Type type_; /* these are passed to the write callback */ QByteArray array_; bool cancelled_ = false; /* don't fuck this up */ std::mutex callback_data_mutex_; }; } // namespace HTTP #endif // MINORI_CORE_HTTP_H_