OpenTTD Source  20241121-master-g67a0fccfad
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 <http://www.gnu.org/licenses/>.
6  */
7 
12 #ifndef NETWORK_CORE_HTTP_H
13 #define NETWORK_CORE_HTTP_H
14 
15 #include "tcp.h"
16 
17 constexpr int HTTP_429_TOO_MANY_REQUESTS = 429;
18 
20 struct HTTPCallback {
25  virtual void OnFailure() = 0;
26 
33  virtual void OnReceiveData(std::unique_ptr<char[]> data, size_t length) = 0;
34 
42  virtual bool IsCancelled() const = 0;
43 
45  virtual ~HTTPCallback() = default;
46 };
47 
50 public:
58  static void Connect(const std::string &uri, HTTPCallback *callback, const std::string data = "");
59 
63  static void HTTPReceive();
64 };
65 
70 
75 
76 #endif /* NETWORK_CORE_HTTP_H */
Base socket handler for HTTP traffic.
Definition: http.h:49
static void Connect(const std::string &uri, HTTPCallback *callback, const std::string data="")
Connect to the given URI.
Definition: http_curl.cpp:93
static void HTTPReceive()
Do the receiving for all HTTP connections.
Definition: http_curl.cpp:107
void NetworkHTTPInitialize()
Initialize the HTTP socket handler.
Definition: http_curl.cpp:242
void NetworkHTTPUninitialize()
Uninitialize the HTTP socket handler.
Definition: http_curl.cpp:277
Callback for when the HTTP handler has something to tell us.
Definition: http.h:20
virtual bool IsCancelled() const =0
Check if there is a request to cancel the transfer.
virtual ~HTTPCallback()=default
Silentium.
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.
Basic functions to receive and send TCP packets.