summaryrefslogtreecommitdiffstats
path: root/src/HTTP/UrlClient.cpp
diff options
context:
space:
mode:
authorMattes D <github@xoft.cz>2023-05-10 00:03:15 +0200
committerMattes D <github@xoft.cz>2023-05-19 16:25:12 +0200
commit77f3cfbba80d4cef603fc644a7f3848d5249b039 (patch)
tree2196a3e6a08e724cb25ad76986fc25e3e577e1a7 /src/HTTP/UrlClient.cpp
parentMojangAPI: Removed an unused TLS root CA. (diff)
downloadcuberite-77f3cfbba80d4cef603fc644a7f3848d5249b039.tar
cuberite-77f3cfbba80d4cef603fc644a7f3848d5249b039.tar.gz
cuberite-77f3cfbba80d4cef603fc644a7f3848d5249b039.tar.bz2
cuberite-77f3cfbba80d4cef603fc644a7f3848d5249b039.tar.lz
cuberite-77f3cfbba80d4cef603fc644a7f3848d5249b039.tar.xz
cuberite-77f3cfbba80d4cef603fc644a7f3848d5249b039.tar.zst
cuberite-77f3cfbba80d4cef603fc644a7f3848d5249b039.zip
Diffstat (limited to 'src/HTTP/UrlClient.cpp')
-rw-r--r--src/HTTP/UrlClient.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/HTTP/UrlClient.cpp b/src/HTTP/UrlClient.cpp
index eb52acfee..11e4d2cc1 100644
--- a/src/HTTP/UrlClient.cpp
+++ b/src/HTTP/UrlClient.cpp
@@ -32,7 +32,8 @@ namespace
public:
explicit cBlockingHTTPCallbacks(std::shared_ptr<cEvent> a_Event, AString & a_ResponseBody) :
- m_Event(std::move(a_Event)), m_ResponseBody(a_ResponseBody)
+ m_Event(std::move(a_Event)), m_ResponseBody(a_ResponseBody),
+ m_IsError(false)
{
}
@@ -44,6 +45,7 @@ namespace
void OnError(const AString & a_ErrorMsg) override
{
LOGERROR("%s %d: HTTP Error: %s", __FILE__, __LINE__, a_ErrorMsg.c_str());
+ m_IsError = true;
m_Event->Set();
}
@@ -56,6 +58,9 @@ namespace
/** The accumulator for the partial body data, so that OnBodyFinished() can send the entire thing at once. */
AString & m_ResponseBody;
+
+ /** Indicates whether an error was encountered while processing the request. */
+ bool m_IsError;
};
}
@@ -746,14 +751,18 @@ std::pair<bool, AString> cUrlClient::BlockingRequest(
{
auto EvtFinished = std::make_shared<cEvent>();
AString Response;
- auto Callbacks = std::make_unique<cBlockingHTTPCallbacks>(EvtFinished, Response);
- auto [Success, ErrorMessage] = cUrlClient::Request(a_Method, a_URL, std::move(Callbacks), std::move(a_Headers), a_Body, a_Options);
+ auto Callbacks = std::make_shared<cBlockingHTTPCallbacks>(EvtFinished, Response);
+ auto [Success, ErrorMessage] = cUrlClient::Request(a_Method, a_URL, Callbacks, std::move(a_Headers), a_Body, a_Options);
if (Success)
{
if (!EvtFinished->Wait(10000))
{
return std::make_pair(false, "Timeout");
}
+ if (Callbacks->m_IsError)
+ {
+ return std::make_pair(false, AString());
+ }
}
else
{