From 2f0efec7ab0430f4f4858db87b7eecfbccc0f47c Mon Sep 17 00:00:00 2001 From: Stefan Boberg Date: Mon, 29 Sep 2025 10:36:32 +0200 Subject: 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. --- src/zenhttp/httpclientauth.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) (limited to 'src/zenhttp/httpclientauth.cpp') 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 #include #include +#include #include ZEN_THIRD_PARTY_INCLUDES_START -#include #include #include 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) { -- cgit v1.2.3