OpenRCT2/src/openrct2/network/Http.h

74 lines
1.7 KiB
C
Raw Normal View History

/*****************************************************************************
* Copyright (c) 2014-2019 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
2018-07-21 16:17:06 +02:00
# include "../common.h"
2018-06-22 23:02:47 +02:00
2018-07-21 16:17:06 +02:00
# include <functional>
# include <map>
# include <string>
namespace OpenRCT2::Networking::Http
{
2018-06-22 23:02:47 +02:00
enum class Status
{
OK = 200,
NotFound = 404
2018-06-22 23:02:47 +02:00
};
2018-06-22 23:02:47 +02:00
enum class Method
{
GET,
POST,
PUT
};
2018-06-22 23:02:47 +02:00
struct Response
{
Status status;
std::string content_type;
std::string body = "";
std::map<std::string, std::string> header = {};
std::string error = "";
};
2018-06-22 23:02:47 +02:00
struct Request
{
std::string url;
std::map<std::string, std::string> header = {};
Method method = Method::GET;
std::string body = "";
bool forceIPv4 = false;
};
2018-06-22 23:02:47 +02:00
struct Http
{
Http();
~Http();
};
2018-06-22 23:02:47 +02:00
Response Do(const Request& req);
void DoAsync(const Request& req, std::function<void(Response& res)> fn);
2018-06-22 23:02:47 +02:00
/**
* Download a park via HTTP/S from the given URL into a memory buffer. This is
* a blocking operation.
* @param url The URL to download the park from.
* @param outData The data returned.
* @returns The size of the data or 0 if the download failed.
*/
size_t DownloadPark(const char* url, void** outData);
} // namespace OpenRCT2::Networking::Http
#endif // DISABLE_HTTP