aboutsummaryrefslogtreecommitdiff
path: root/src/zenhttp/httpclientauth.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2025-09-29 10:36:32 +0200
committerGitHub Enterprise <[email protected]>2025-09-29 10:36:32 +0200
commit2f0efec7ab0430f4f4858db87b7eecfbccc0f47c (patch)
tree80ce35992a220260cf070fac739626f555de738a /src/zenhttp/httpclientauth.cpp
parentfixed race condition in zen::logging::Get (#519) (diff)
downloadzen-2f0efec7ab0430f4f4858db87b7eecfbccc0f47c.tar.xz
zen-2f0efec7ab0430f4f4858db87b7eecfbccc0f47c.zip
make cpr a HttpClient implementation detail (#517)
these changes remove cpr from anything which is not `HttpClient` internals. The goal is to eventually replace cpr with a more direct curl interface to eliminate cpr since it's proven problematic due to their development practices which frequently breaks APIs and prevents us from updating vcpkg. But this PR is limited to refactoring existing cpr code to use `HttpClient` instead.
Diffstat (limited to 'src/zenhttp/httpclientauth.cpp')
-rw-r--r--src/zenhttp/httpclientauth.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/zenhttp/httpclientauth.cpp b/src/zenhttp/httpclientauth.cpp
index 4bbc6405b..4438fc137 100644
--- a/src/zenhttp/httpclientauth.cpp
+++ b/src/zenhttp/httpclientauth.cpp
@@ -9,11 +9,11 @@
#include <zencore/timer.h>
#include <zencore/uid.h>
#include <zenhttp/auth/authmgr.h>
+#include <zenhttp/httpclient.h>
#include <ctime>
ZEN_THIRD_PARTY_INCLUDES_START
-#include <cpr/cpr.h>
#include <fmt/format.h>
#include <json11.hpp>
ZEN_THIRD_PARTY_INCLUDES_END
@@ -47,18 +47,22 @@ namespace zen { namespace httpclientauth {
OAuthParams.ClientId,
OAuthParams.ClientSecret);
- cpr::Response Response = cpr::Post(cpr::Url{OAuthParams.Url},
- cpr::Header{{"Content-Type", "application/x-www-form-urlencoded"}},
- cpr::Body{std::move(Body)});
+ HttpClient Http{OAuthParams.Url};
- if (Response.error || Response.status_code != 200)
+ IoBuffer Payload{IoBuffer::Wrap, Body.data(), Body.size()};
+
+ // TODO: ensure this gets the right Content-Type passed along
+
+ HttpClient::Response Response = Http.Post("", Payload, {{"Content-Type", "application/x-www-form-urlencoded"}});
+
+ if (!Response || Response.StatusCode != HttpResponseCode::OK)
{
- ZEN_WARN("Failed fetching OAuth access token {}. Reason: '{}'", OAuthParams.Url, Response.reason);
+ ZEN_WARN("Failed fetching OAuth access token {}. Reason: '{}'", OAuthParams.Url, Response.ErrorMessage(""));
return HttpClientAccessToken{};
}
std::string JsonError;
- json11::Json Json = json11::Json::parse(Response.text, JsonError);
+ json11::Json Json = json11::Json::parse(std::string{Response.AsText()}, JsonError);
if (JsonError.empty() == false)
{