OpenTTD Source 20260311-master-g511d3794ce
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
13#include "tcp.h"
14
15constexpr int HTTP_429_TOO_MANY_REQUESTS = 429;
16
23 virtual void OnFailure() = 0;
24
31 virtual void OnReceiveData(std::unique_ptr<char[]> data, size_t length) = 0;
32
40 virtual bool IsCancelled() const = 0;
41
43 virtual ~HTTPCallback() = default;
44};
45
48public:
56 static void Connect(std::string_view uri, HTTPCallback *callback, std::string &&data = "");
57
61 static void HTTPReceive();
62};
63
68
73
74#endif /* NETWORK_CORE_HTTP_H */
Base socket handler for HTTP traffic.
Definition http.h:47
static void Connect(std::string_view uri, HTTPCallback *callback, std::string &&data="")
Connect to the given URI.
Definition http_curl.cpp:93
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:15
void NetworkHTTPUninitialize()
Uninitialize the HTTP socket handler.
Callback for when the HTTP handler has something to tell us.
Definition http.h:18
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.
Basic functions to receive and send TCP packets.