mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-02-01 19:25:12 +01:00
* If the master server vanishes make sure to register again, cleanup * Update changelog.txt * Fix uncaught exceptions for the HTTP impl just silently failing * Don't set the future object to an empty one, that is always pending * Improve the console messages, adjust retry time
75 lines
1.6 KiB
C++
75 lines
1.6 KiB
C++
/*****************************************************************************
|
|
* Copyright (c) 2014-2025 OpenRCT2 developers
|
|
*
|
|
* For a complete list of all authors, please refer to contributors.md
|
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
|
*
|
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
|
*****************************************************************************/
|
|
|
|
#pragma once
|
|
|
|
#ifndef DISABLE_HTTP
|
|
|
|
#include <functional>
|
|
#include <future>
|
|
#include <map>
|
|
#include <string>
|
|
|
|
namespace OpenRCT2::Http
|
|
{
|
|
enum class Status
|
|
{
|
|
Invalid = 0,
|
|
Error = 1,
|
|
Ok = 200,
|
|
NotFound = 404
|
|
};
|
|
|
|
enum class Method
|
|
{
|
|
GET,
|
|
POST,
|
|
PUT
|
|
};
|
|
|
|
struct Response
|
|
{
|
|
Status status{};
|
|
std::string content_type;
|
|
std::string body;
|
|
std::map<std::string, std::string> header = {};
|
|
std::string error;
|
|
};
|
|
|
|
struct Request
|
|
{
|
|
std::string url;
|
|
std::map<std::string, std::string> header;
|
|
Method method = Method::GET;
|
|
std::string body;
|
|
bool forceIPv4{};
|
|
};
|
|
|
|
Response Do(const Request& req);
|
|
|
|
inline auto DoAsync(const Request& req, std::function<void(Response& res)> fn)
|
|
{
|
|
return std::async(std::launch::async, [=]() {
|
|
Response res{};
|
|
try
|
|
{
|
|
res = Do(req);
|
|
}
|
|
catch (std::exception& e)
|
|
{
|
|
res.error = e.what();
|
|
return;
|
|
}
|
|
fn(res);
|
|
});
|
|
}
|
|
} // namespace OpenRCT2::Http
|
|
|
|
#endif // DISABLE_HTTP
|