diff options
author | ouwou <26526779+ouwou@users.noreply.github.com> | 2022-08-12 18:35:58 -0400 |
---|---|---|
committer | ouwou <26526779+ouwou@users.noreply.github.com> | 2022-08-12 18:35:58 -0400 |
commit | 6a5ecb4d9584f7276cf1d592c95811a66943f61c (patch) | |
tree | 2c09268db37461ce9e1882789183c508bb36dd4a /src/discord/httpclient.cpp | |
parent | dc28eae95a46c3079fcc76b3425ffa37844dd37d (diff) | |
parent | f60cea2216dd9677cb9105364cdaa778a0c187db (diff) | |
download | abaddon-portaudio-6a5ecb4d9584f7276cf1d592c95811a66943f61c.tar.gz abaddon-portaudio-6a5ecb4d9584f7276cf1d592c95811a66943f61c.zip |
Merge branch 'attachments'
Diffstat (limited to 'src/discord/httpclient.cpp')
-rw-r--r-- | src/discord/httpclient.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/discord/httpclient.cpp b/src/discord/httpclient.cpp index cd699f0..d13246d 100644 --- a/src/discord/httpclient.cpp +++ b/src/discord/httpclient.cpp @@ -124,6 +124,25 @@ void HTTPClient::MakeGET(const std::string &path, const std::function<void(http: })); } +http::request HTTPClient::CreateRequest(http::EMethod method, std::string path) { + http::request req(method, m_api_base + path); + req.set_header("Authorization", m_authorization); + req.set_user_agent(!m_agent.empty() ? m_agent : "Abaddon"); +#ifdef USE_LOCAL_PROXY + req.set_proxy("http://127.0.0.1:8888"); + req.set_verify_ssl(false); +#endif + return req; +} + +void HTTPClient::Execute(http::request &&req, const std::function<void(http::response_type r)> &cb) { + printf("%s %s\n", req.get_method(), req.get_url().c_str()); + m_futures.push_back(std::async(std::launch::async, [this, cb, req = std::move(req)]() mutable { + auto res = req.execute(); + OnResponse(res, cb); + })); +} + void HTTPClient::CleanupFutures() { for (auto it = m_futures.begin(); it != m_futures.end();) { if (it->wait_for(std::chrono::seconds(0)) == std::future_status::ready) |