mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-03 00:16:50 +00:00
v2.0.84
- proxy tweaking
This commit is contained in:
parent
3b479abf64
commit
2781179b4b
@ -291,36 +291,53 @@ void PreGame(const std::string& GamePath){
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void set_headers(httplib::Response& res) {
|
||||||
|
res.set_header("Access-Control-Allow-Origin", "*");
|
||||||
|
}
|
||||||
|
|
||||||
void StartProxy() {
|
void StartProxy() {
|
||||||
std::thread proxy([&](){
|
std::thread proxy([&](){
|
||||||
httplib::Server HTTPProxy;
|
httplib::Server HTTPProxy;
|
||||||
|
httplib::Headers headers = {
|
||||||
|
{"User-Agent", "BeamMP-Launcher/" + GetVer() + GetPatch()},
|
||||||
|
{"Accept", "*/*"}
|
||||||
|
};
|
||||||
|
std::string pattern = "/:any1";
|
||||||
|
for (int i = 2; i <= 4; i++) {
|
||||||
|
HTTPProxy.Get(pattern, [&](const httplib::Request &req, httplib::Response &res) {
|
||||||
|
httplib::Client cli("https://backend.beammp.com");
|
||||||
|
set_headers(res);
|
||||||
|
if (req.has_header("X-BMP-Authentication")) {
|
||||||
|
headers.emplace("X-BMP-Authentication", PrivateKey);
|
||||||
|
}
|
||||||
|
if (req.has_header("X-API-Version")) {
|
||||||
|
headers.emplace("X-API-Version", req.get_header_value("X-API-Version"));
|
||||||
|
}
|
||||||
|
if (auto cli_res = cli.Get(req.path, headers); cli_res) {
|
||||||
|
res.set_content(cli_res->body, cli_res->get_header_value("Content-Type"));
|
||||||
|
} else {
|
||||||
|
res.set_content(to_string(cli_res.error()), "text/plain");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
HTTPProxy.Get("/:any", [](const httplib::Request& req, httplib::Response& res) {
|
HTTPProxy.Post(pattern, [&](const httplib::Request &req, httplib::Response &res) {
|
||||||
httplib::Client cli("https://backend.beammp.com");
|
httplib::Client cli("https://backend.beammp.com");
|
||||||
auto headers = req.headers;
|
set_headers(res);
|
||||||
if (req.has_header("X-BMP-Authentication")) {
|
if (req.has_header("X-BMP-Authentication")) {
|
||||||
headers.emplace("X-BMP-Authentication", PrivateKey);
|
headers.emplace("X-BMP-Authentication", PrivateKey);
|
||||||
}
|
}
|
||||||
if (auto cli_res = cli.Get(req.path, headers); cli_res) {
|
if (req.has_header("X-API-Version")) {
|
||||||
res.set_content(cli_res->body,cli_res->get_header_value("Content-Type"));
|
headers.emplace("X-API-Version", req.get_header_value("X-API-Version"));
|
||||||
} else {
|
}
|
||||||
res.set_content(to_string(cli_res.error()), "text/plain");
|
if (auto cli_res = cli.Post(req.path, headers, req.body,
|
||||||
}
|
req.get_header_value("Content-Type")); cli_res) {
|
||||||
});
|
res.set_content(cli_res->body, cli_res->get_header_value("Content-Type"));
|
||||||
|
} else {
|
||||||
HTTPProxy.Post("/:any", [](const httplib::Request& req, httplib::Response& res) {
|
res.set_content(to_string(cli_res.error()), "text/plain");
|
||||||
httplib::Client cli("https://backend.beammp.com");
|
}
|
||||||
auto headers = req.headers;
|
});
|
||||||
if (req.has_header("X-BMP-Authentication")) {
|
pattern += "/:any" + std::to_string(i);
|
||||||
headers.emplace("X-BMP-Authentication", PrivateKey);
|
}
|
||||||
}
|
|
||||||
if (auto cli_res = cli.Post(req.path, headers, req.body, req.get_header_value("Content-Type")); cli_res) {
|
|
||||||
res.set_content(cli_res->body,cli_res->get_header_value("Content-Type"));
|
|
||||||
} else {
|
|
||||||
res.set_content(to_string(cli_res.error()), "text/plain");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
ProxyPort = HTTPProxy.bind_to_any_port("0.0.0.0");
|
ProxyPort = HTTPProxy.bind_to_any_port("0.0.0.0");
|
||||||
HTTPProxy.listen_after_bind();
|
HTTPProxy.listen_after_bind();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user