From 49685c39895af67d7ffcc50fdc02150b6ee44f72 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Tue, 5 Apr 2022 22:01:53 -0400 Subject: fix up a bunch of clang-tidy stuff mostly changing references, which i hope doesnt break stuff with models (TreeRow, iterators) since they gave me some strange problems in the past --- src/discord/httpclient.cpp | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) (limited to 'src/discord/httpclient.cpp') diff --git a/src/discord/httpclient.cpp b/src/discord/httpclient.cpp index 05474df..f5b640c 100644 --- a/src/discord/httpclient.cpp +++ b/src/discord/httpclient.cpp @@ -1,5 +1,7 @@ #include "httpclient.hpp" +#include + //#define USE_LOCAL_PROXY HTTPClient::HTTPClient() { m_dispatcher.connect(sigc::mem_fun(*this, &HTTPClient::RunCallbacks)); @@ -10,19 +12,19 @@ void HTTPClient::SetBase(const std::string &url) { } void HTTPClient::SetUserAgent(std::string agent) { - m_agent = agent; + m_agent = std::move(agent); } void HTTPClient::SetAuth(std::string auth) { - m_authorization = auth; + m_authorization = std::move(auth); } -void HTTPClient::MakeDELETE(const std::string &path, std::function cb) { +void HTTPClient::MakeDELETE(const std::string &path, const std::function &cb) { printf("DELETE %s\n", path.c_str()); m_futures.push_back(std::async(std::launch::async, [this, path, cb] { http::request req(http::REQUEST_DELETE, m_api_base + path); req.set_header("Authorization", m_authorization); - req.set_user_agent(m_agent != "" ? m_agent : "Abaddon"); + 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); @@ -34,13 +36,13 @@ void HTTPClient::MakeDELETE(const std::string &path, std::function cb) { +void HTTPClient::MakePATCH(const std::string &path, const std::string &payload, const std::function &cb) { printf("PATCH %s\n", path.c_str()); m_futures.push_back(std::async(std::launch::async, [this, path, cb, payload] { http::request req(http::REQUEST_PATCH, m_api_base + path); req.set_header("Authorization", m_authorization); req.set_header("Content-Type", "application/json"); - req.set_user_agent(m_agent != "" ? m_agent : "Abaddon"); + req.set_user_agent(!m_agent.empty() ? m_agent : "Abaddon"); req.set_body(payload); #ifdef USE_LOCAL_PROXY req.set_proxy("http://127.0.0.1:8888"); @@ -53,13 +55,13 @@ void HTTPClient::MakePATCH(const std::string &path, const std::string &payload, })); } -void HTTPClient::MakePOST(const std::string &path, const std::string &payload, std::function cb) { +void HTTPClient::MakePOST(const std::string &path, const std::string &payload, const std::function &cb) { printf("POST %s\n", path.c_str()); m_futures.push_back(std::async(std::launch::async, [this, path, cb, payload] { http::request req(http::REQUEST_POST, m_api_base + path); req.set_header("Authorization", m_authorization); req.set_header("Content-Type", "application/json"); - req.set_user_agent(m_agent != "" ? m_agent : "Abaddon"); + req.set_user_agent(!m_agent.empty() ? m_agent : "Abaddon"); req.set_body(payload); #ifdef USE_LOCAL_PROXY req.set_proxy("http://127.0.0.1:8888"); @@ -72,14 +74,14 @@ void HTTPClient::MakePOST(const std::string &path, const std::string &payload, s })); } -void HTTPClient::MakePUT(const std::string &path, const std::string &payload, std::function cb) { +void HTTPClient::MakePUT(const std::string &path, const std::string &payload, const std::function &cb) { printf("PUT %s\n", path.c_str()); m_futures.push_back(std::async(std::launch::async, [this, path, cb, payload] { http::request req(http::REQUEST_PUT, m_api_base + path); req.set_header("Authorization", m_authorization); - if (payload != "") + if (!payload.empty()) req.set_header("Content-Type", "application/json"); - req.set_user_agent(m_agent != "" ? m_agent : "Abaddon"); + req.set_user_agent(!m_agent.empty() ? m_agent : "Abaddon"); req.set_body(payload); #ifdef USE_LOCAL_PROXY req.set_proxy("http://127.0.0.1:8888"); @@ -92,13 +94,13 @@ void HTTPClient::MakePUT(const std::string &path, const std::string &payload, st })); } -void HTTPClient::MakeGET(const std::string &path, std::function cb) { +void HTTPClient::MakeGET(const std::string &path, const std::function &cb) { printf("GET %s\n", path.c_str()); m_futures.push_back(std::async(std::launch::async, [this, path, cb] { http::request req(http::REQUEST_GET, m_api_base + path); req.set_header("Authorization", m_authorization); req.set_header("Content-Type", "application/json"); - req.set_user_agent(m_agent != "" ? m_agent : "Abaddon"); + 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); @@ -126,11 +128,11 @@ void HTTPClient::RunCallbacks() { m_mutex.unlock(); } -void HTTPClient::OnResponse(const http::response_type &r, std::function cb) { +void HTTPClient::OnResponse(const http::response_type &r, const std::function &cb) { CleanupFutures(); try { m_mutex.lock(); - m_queue.push([this, r, cb] { cb(r); }); + m_queue.push([r, cb] { cb(r); }); m_dispatcher.emit(); m_mutex.unlock(); } catch (const std::exception &e) { -- cgit v1.2.3