OpenTTD Source 20261112-master-gbcbec5e63f
http.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef NETWORK_CORE_HTTP_H
11#define NETWORK_CORE_HTTP_H
12
13constexpr int HTTP_429_TOO_MANY_REQUESTS = 429;
14
21 virtual void OnFailure() = 0;
22
29 virtual void OnReceiveData(std::unique_ptr<char[]> data, size_t length) = 0;
30
38 virtual bool IsCancelled() const = 0;
39
41 virtual ~HTTPCallback() = default;
42};
43
46public:
54 static void Connect(std::string_view uri, HTTPCallback *callback, std::string &&data = "");
55
59 static void HTTPReceive();
60};
61
66
71
72#endif /* NETWORK_CORE_HTTP_H */
Base socket handler for HTTP traffic.
Definition http.h:45
static void Connect(std::string_view uri, HTTPCallback *callback, std::string &&data="")
Connect to the given URI.
Definition http_curl.cpp:92
static void HTTPReceive()
Do the receiving for all HTTP connections.
void NetworkHTTPInitialize()
Initialize the HTTP socket handler.
constexpr int HTTP_429_TOO_MANY_REQUESTS
HTTP error code for when the client is doing too many requests.
Definition http.h:13
void NetworkHTTPUninitialize()
Uninitialize the HTTP socket handler.
Callback for when the HTTP handler has something to tell us.
Definition http.h:16
virtual bool IsCancelled() const =0
Check if there is a request to cancel the transfer.
virtual ~HTTPCallback()=default
Ensure the destructor of the sub classes are called as well.
virtual void OnFailure()=0
An error has occurred and the connection has been closed.
virtual void OnReceiveData(std::unique_ptr< char[]> data, size_t length)=0
We're receiving data.