mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2026-08-27 04:27:42 +00:00
Made http get and post try twice
This commit is contained in:
@@ -146,7 +146,18 @@ std::string Http::GET(std::string url, unsigned int* status, const bool& redirec
|
|||||||
if (res != CURLE_OK) {
|
if (res != CURLE_OK) {
|
||||||
beammp_error("GET to " + url + " failed: " + std::string(curl_easy_strerror(res)));
|
beammp_error("GET to " + url + " failed: " + std::string(curl_easy_strerror(res)));
|
||||||
beammp_error("Curl error: " + std::string(errbuf));
|
beammp_error("Curl error: " + std::string(errbuf));
|
||||||
|
if (!redirect) {
|
||||||
|
return Http::ErrorString;
|
||||||
|
}
|
||||||
RegionHandler::TopLevelDomainFailed();
|
RegionHandler::TopLevelDomainFailed();
|
||||||
|
url = RegionHandler::RedirectURL(url);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||||
|
res = curl_easy_perform(curl);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
beammp_error("GET to " + url + " failed: " + std::string(curl_easy_strerror(res)));
|
||||||
|
beammp_error("Curl error: " + std::string(errbuf));
|
||||||
|
return Http::ErrorString;
|
||||||
|
}
|
||||||
return Http::ErrorString;
|
return Http::ErrorString;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -203,7 +214,18 @@ std::string Http::POST(std::string url, const std::string& body, const std::stri
|
|||||||
if (res != CURLE_OK) {
|
if (res != CURLE_OK) {
|
||||||
beammp_error("POST to " + url + " failed: " + std::string(curl_easy_strerror(res)));
|
beammp_error("POST to " + url + " failed: " + std::string(curl_easy_strerror(res)));
|
||||||
beammp_error("Curl error: " + std::string(errbuf));
|
beammp_error("Curl error: " + std::string(errbuf));
|
||||||
|
if (!redirect) {
|
||||||
|
return Http::ErrorString;
|
||||||
|
}
|
||||||
RegionHandler::TopLevelDomainFailed();
|
RegionHandler::TopLevelDomainFailed();
|
||||||
|
url = RegionHandler::RedirectURL(url);
|
||||||
|
curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
|
||||||
|
res = curl_easy_perform(curl);
|
||||||
|
if (res != CURLE_OK) {
|
||||||
|
beammp_error("GET to " + url + " failed: " + std::string(curl_easy_strerror(res)));
|
||||||
|
beammp_error("Curl error: " + std::string(errbuf));
|
||||||
|
return Http::ErrorString;
|
||||||
|
}
|
||||||
return Http::ErrorString;
|
return Http::ErrorString;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -298,10 +298,6 @@ void TConsole::Command_NetTest(const std::string& cmd, const std::vector<std::st
|
|||||||
|
|
||||||
std::string T = Http::GET(
|
std::string T = Http::GET(
|
||||||
Application::GetServerCheckUrl() + "/api/v2/beammp/" + std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port)), &status);
|
Application::GetServerCheckUrl() + "/api/v2/beammp/" + std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port)), &status);
|
||||||
if (T == Http::ErrorString || status != 200) {
|
|
||||||
RegionHandler::TopLevelDomainFailed();
|
|
||||||
T = Http::GET(Application::GetServerCheckUrl() + "/api/v2/beammp/" + std::to_string(Application::Settings.getAsInt(Settings::Key::General_Port)), &status);
|
|
||||||
}
|
|
||||||
|
|
||||||
beammp_debugf("Status and response from Server Check API: {0}, {1}", status, T);
|
beammp_debugf("Status and response from Server Check API: {0}, {1}", status, T);
|
||||||
|
|
||||||
|
|||||||
@@ -63,10 +63,6 @@ void THeartbeatThread::operator()() {
|
|||||||
bool Ok = false;
|
bool Ok = false;
|
||||||
for (const auto& Url : Application::GetBackendUrlsInOrder()) {
|
for (const auto& Url : Application::GetBackendUrlsInOrder()) {
|
||||||
T = Http::POST(Url + Target, Body, "application/json", &ResponseCode, { { "api-v", "2" } });
|
T = Http::POST(Url + Target, Body, "application/json", &ResponseCode, { { "api-v", "2" } });
|
||||||
if (T == Http::ErrorString || ResponseCode != 200) {
|
|
||||||
RegionHandler::TopLevelDomainFailed();
|
|
||||||
T = Http::POST(Url + Target, Body, "application/json", &ResponseCode, { { "api-v", "2" } });
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!Application::Settings.getAsBool(Settings::Key::General_Private)) {
|
if (!Application::Settings.getAsBool(Settings::Key::General_Private)) {
|
||||||
beammp_debug("Backend response was: `" + T + "`");
|
beammp_debug("Backend response was: `" + T + "`");
|
||||||
|
|||||||
@@ -458,10 +458,6 @@ std::shared_ptr<TClient> TNetwork::Authentication(TConnection&& RawConnection) {
|
|||||||
|
|
||||||
unsigned int ResponseCode = 0;
|
unsigned int ResponseCode = 0;
|
||||||
AuthResStr = Http::POST(Application::GetBackendUrlForAuth() + Target, AuthReq.dump(), "application/json", &ResponseCode);
|
AuthResStr = Http::POST(Application::GetBackendUrlForAuth() + Target, AuthReq.dump(), "application/json", &ResponseCode);
|
||||||
if (AuthResStr == Http::ErrorString || ResponseCode != 200) {
|
|
||||||
RegionHandler::TopLevelDomainFailed();
|
|
||||||
AuthResStr = Http::POST(Application::GetBackendUrlForAuth() + Target, AuthReq.dump(), "application/json", &ResponseCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
beammp_debugf("Invalid json sent by client, kicking: {}", e.what());
|
beammp_debugf("Invalid json sent by client, kicking: {}", e.what());
|
||||||
|
|||||||
Reference in New Issue
Block a user