mirror of
https://github.com/BeamMP/BeamMP-Server.git
synced 2025-08-17 16:57:05 +00:00
Http: add Status::ToString method, use to report errors to sentry for custom fingerprint
This commit is contained in:
parent
e8665bfb72
commit
f98c8dabb0
@ -6,4 +6,7 @@
|
|||||||
namespace Http {
|
namespace Http {
|
||||||
std::string GET(const std::string& host, int port, const std::string& target);
|
std::string GET(const std::string& host, int port, const std::string& target);
|
||||||
std::string POST(const std::string& host, const std::string& target, const std::unordered_map<std::string, std::string>& fields, const std::string& body, bool json, int* status = nullptr);
|
std::string POST(const std::string& host, const std::string& target, const std::unordered_map<std::string, std::string>& fields, const std::string& body, bool json, int* status = nullptr);
|
||||||
|
namespace Status {
|
||||||
|
std::string ToString(int code);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
75
src/Http.cpp
75
src/Http.cpp
@ -7,6 +7,7 @@
|
|||||||
#include <boost/asio/ip/tcp.hpp>
|
#include <boost/asio/ip/tcp.hpp>
|
||||||
#include <boost/beast.hpp>
|
#include <boost/beast.hpp>
|
||||||
#include <boost/beast/ssl.hpp>
|
#include <boost/beast/ssl.hpp>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
namespace beast = boost::beast; // from <boost/beast.hpp>
|
namespace beast = boost::beast; // from <boost/beast.hpp>
|
||||||
namespace http = beast::http; // from <boost/beast/http.hpp>
|
namespace http = beast::http; // from <boost/beast/http.hpp>
|
||||||
@ -166,3 +167,77 @@ std::string Http::POST(const std::string& host, const std::string& target, const
|
|||||||
return "-1";
|
return "-1";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RFC 2616, RFC 7231
|
||||||
|
static std::map<size_t, const char*> Map = {
|
||||||
|
{ 100, "Continue" },
|
||||||
|
{ 101, "Switching Protocols" },
|
||||||
|
{ 102, "Processing" },
|
||||||
|
{ 103, "Early Hints" },
|
||||||
|
{ 200, "OK" },
|
||||||
|
{ 201, "Created" },
|
||||||
|
{ 202, "Accepted" },
|
||||||
|
{ 203, "Non-Authoritative Information" },
|
||||||
|
{ 204, "No Content" },
|
||||||
|
{ 205, "Reset Content" },
|
||||||
|
{ 206, "Partial Content" },
|
||||||
|
{ 207, "Multi-Status" },
|
||||||
|
{ 208, "Already Reported" },
|
||||||
|
{ 226, "IM Used" },
|
||||||
|
{ 300, "Multiple Choices" },
|
||||||
|
{ 301, "Moved Permanently" },
|
||||||
|
{ 302, "Found" },
|
||||||
|
{ 303, "See Other" },
|
||||||
|
{ 304, "Not Modified" },
|
||||||
|
{ 305, "Use Proxy" },
|
||||||
|
{ 306, "(Unused)" },
|
||||||
|
{ 307, "Temporary Redirect" },
|
||||||
|
{ 308, "Permanent Redirect" },
|
||||||
|
{ 400, "Bad Request" },
|
||||||
|
{ 401, "Unauthorized" },
|
||||||
|
{ 402, "Payment Required" },
|
||||||
|
{ 403, "Forbidden" },
|
||||||
|
{ 404, "Not Found" },
|
||||||
|
{ 405, "Method Not Allowed" },
|
||||||
|
{ 406, "Not Acceptable" },
|
||||||
|
{ 407, "Proxy Authentication Required" },
|
||||||
|
{ 408, "Request Timeout" },
|
||||||
|
{ 409, "Conflict" },
|
||||||
|
{ 410, "Gone" },
|
||||||
|
{ 411, "Length Required" },
|
||||||
|
{ 412, "Precondition Failed" },
|
||||||
|
{ 413, "Payload Too Large" },
|
||||||
|
{ 414, "URI Too Long" },
|
||||||
|
{ 415, "Unsupported Media Type" },
|
||||||
|
{ 416, "Range Not Satisfiable" },
|
||||||
|
{ 417, "Expectation Failed" },
|
||||||
|
{ 421, "Misdirected Request" },
|
||||||
|
{ 422, "Unprocessable Entity" },
|
||||||
|
{ 423, "Locked" },
|
||||||
|
{ 424, "Failed Dependency" },
|
||||||
|
{ 425, "Too Early" },
|
||||||
|
{ 426, "Upgrade Required" },
|
||||||
|
{ 428, "Precondition Required" },
|
||||||
|
{ 429, "Too Many Requests" },
|
||||||
|
{ 431, "Request Header Fields Too Large" },
|
||||||
|
{ 451, "Unavailable For Legal Reasons" },
|
||||||
|
{ 500, "Internal Server Error" },
|
||||||
|
{ 501, "Not Implemented" },
|
||||||
|
{ 502, "Bad Gateway" },
|
||||||
|
{ 503, "Service Unavailable" },
|
||||||
|
{ 504, "Gateway Timeout" },
|
||||||
|
{ 505, "HTTP Version Not Supported" },
|
||||||
|
{ 506, "Variant Also Negotiates" },
|
||||||
|
{ 507, "Insufficient Storage" },
|
||||||
|
{ 508, "Loop Detected" },
|
||||||
|
{ 510, "Not Extended" },
|
||||||
|
{ 511, "Network Authentication Required" },
|
||||||
|
};
|
||||||
|
|
||||||
|
std::string Http::Status::ToString(int code) {
|
||||||
|
if (Map.find(code) != Map.end()) {
|
||||||
|
return Map.at(code);
|
||||||
|
} else {
|
||||||
|
return "Unassigned";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -47,7 +47,7 @@ void THeartbeatThread::operator()() {
|
|||||||
#if DEBUG
|
#if DEBUG
|
||||||
debug("sending log to sentry: " + std::to_string(status) + " for " + transaction);
|
debug("sending log to sentry: " + std::to_string(status) + " for " + transaction);
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
Sentry.Log(SentryLevel::Error, "default", "unexpected backend response (" + std::to_string(status) + ")");
|
Sentry.Log(SentryLevel::Error, "default", Http::Status::ToString(status) + " (" + std::to_string(status) + ")");
|
||||||
};
|
};
|
||||||
|
|
||||||
auto Target = "/heartbeat";
|
auto Target = "/heartbeat";
|
||||||
@ -66,7 +66,7 @@ void THeartbeatThread::operator()() {
|
|||||||
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
std::this_thread::sleep_for(std::chrono::milliseconds(500));
|
||||||
T = Http::POST(Application::GetBackup2Hostname(), Target, {}, Body, false, &ResponseCode);
|
T = Http::POST(Application::GetBackup2Hostname(), Target, {}, Body, false, &ResponseCode);
|
||||||
if (T.substr(0, 2) != "20" || ResponseCode != 200) {
|
if (T.substr(0, 2) != "20" || ResponseCode != 200) {
|
||||||
warn("Backend system refused server! Server might not show in the public list");
|
warn("Backend system refused server! Server will not show in the public server list.");
|
||||||
isAuth = false;
|
isAuth = false;
|
||||||
SentryReportError(Application::GetBackup2Hostname() + Target, ResponseCode);
|
SentryReportError(Application::GetBackup2Hostname() + Target, ResponseCode);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user