summaryrefslogtreecommitdiff
path: root/discord/http.cpp
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2020-11-27 01:37:01 -0500
committerouwou <26526779+ouwou@users.noreply.github.com>2020-11-27 01:37:01 -0500
commitae77bfd1d1df50d8159e50fee4f7c5616cffe1b8 (patch)
tree4c1ac7be700ea46432ede85a0d128394e3b31b45 /discord/http.cpp
parent1463d8da9e1b4c49021e6fa75795e2cd054b6227 (diff)
downloadabaddon-portaudio-ae77bfd1d1df50d8159e50fee4f7c5616cffe1b8.tar.gz
abaddon-portaudio-ae77bfd1d1df50d8159e50fee4f7c5616cffe1b8.zip
set user-agent through ini
Diffstat (limited to 'discord/http.cpp')
-rw-r--r--discord/http.cpp35
1 files changed, 25 insertions, 10 deletions
diff --git a/discord/http.cpp b/discord/http.cpp
index 41f6c17..a435aef 100644
--- a/discord/http.cpp
+++ b/discord/http.cpp
@@ -6,6 +6,10 @@ HTTPClient::HTTPClient(std::string api_base)
m_dispatcher.connect(sigc::mem_fun(*this, &HTTPClient::RunCallbacks));
}
+void HTTPClient::SetUserAgent(std::string agent) {
+ m_agent = agent;
+}
+
void HTTPClient::SetAuth(std::string auth) {
m_authorization = auth;
}
@@ -16,16 +20,18 @@ void HTTPClient::MakeDELETE(std::string path, std::function<void(cpr::Response r
auto headers = cpr::Header {
{ "Authorization", m_authorization },
};
+ auto ua = cpr::UserAgent {m_agent != "" ? m_agent : "Abaddon" };
+
#ifdef USE_LOCAL_PROXY
m_futures.push_back(cpr::DeleteCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers,
+ url, headers, ua,
cpr::Proxies { { "http", "127.0.0.1:8888" }, { "https", "127.0.0.1:8888" } },
cpr::VerifySsl { false }));
#else
m_futures.push_back(cpr::DeleteCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers));
+ url, headers, ua));
#endif
}
@@ -36,17 +42,19 @@ void HTTPClient::MakePATCH(std::string path, std::string payload, std::function<
{ "Authorization", m_authorization },
{ "Content-Type", "application/json" },
};
+ auto ua = cpr::UserAgent { m_agent != "" ? m_agent : "Abaddon" };
+
auto body = cpr::Body { payload };
#ifdef USE_LOCAL_PROXY
m_futures.push_back(cpr::PatchCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers, body,
+ url, headers, body, ua,
cpr::Proxies { { "http", "127.0.0.1:8888" }, { "https", "127.0.0.1:8888" } },
cpr::VerifySsl { false }));
#else
m_futures.push_back(cpr::PatchCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers, body));
+ url, headers, body, ua));
#endif
}
@@ -57,17 +65,19 @@ void HTTPClient::MakePOST(std::string path, std::string payload, std::function<v
{ "Authorization", m_authorization },
{ "Content-Type", "application/json" },
};
+ auto ua = cpr::UserAgent { m_agent != "" ? m_agent : "Abaddon" };
+
auto body = cpr::Body { payload };
#ifdef USE_LOCAL_PROXY
m_futures.push_back(cpr::PostCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers, body,
+ url, headers, body, ua,
cpr::Proxies { { "http", "127.0.0.1:8888" }, { "https", "127.0.0.1:8888" } },
cpr::VerifySsl { false }));
#else
m_futures.push_back(cpr::PostCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers, body));
+ url, headers, body, ua));
#endif
}
@@ -78,17 +88,19 @@ void HTTPClient::MakePUT(std::string path, std::string payload, std::function<vo
{ "Authorization", m_authorization },
{ "Content-Type", "application/json" },
};
+ auto ua = cpr::UserAgent { m_agent != "" ? m_agent : "Abaddon" };
+
auto body = cpr::Body { payload };
#ifdef USE_LOCAL_PROXY
m_futures.push_back(cpr::PutCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers, body,
+ url, headers, body, ua,
cpr::Proxies { { "http", "127.0.0.1:8888" }, { "https", "127.0.0.1:8888" } },
cpr::VerifySsl { false }));
#else
m_futures.push_back(cpr::PutCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers, body));
+ url, headers, body, ua));
#endif
}
@@ -99,16 +111,19 @@ void HTTPClient::MakeGET(std::string path, std::function<void(cpr::Response r)>
{ "Authorization", m_authorization },
{ "Content-Type", "application/json" },
};
+ auto ua = cpr::UserAgent { m_agent != "" ? m_agent : "Abaddon" };
+
+ auto x = cpr::UserAgent {};
#ifdef USE_LOCAL_PROXY
m_futures.push_back(cpr::GetCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers,
+ url, headers, ua,
cpr::Proxies { { "http", "127.0.0.1:8888" }, { "https", "127.0.0.1:8888" } },
cpr::VerifySsl { false }));
#else
m_futures.push_back(cpr::GetCallback(
std::bind(&HTTPClient::OnResponse, this, std::placeholders::_1, cb),
- url, headers));
+ url, headers, ua));
#endif
}