OpenTTD Source 20241224-master-gee860a5c8e
|
Single HTTP request. More...
Public Member Functions | |
NetworkHTTPRequest (const std::string &uri, HTTPCallback *callback, const std::string &data) | |
Create a new HTTP request. | |
~NetworkHTTPRequest () | |
Destructor of the HTTP request. | |
NetworkHTTPRequest (const std::wstring &uri, HTTPCallback *callback, const std::string &data) | |
Create a new HTTP request. | |
void | Connect () |
Start the HTTP request handling. | |
bool | Receive () |
Poll and process the HTTP request/response. | |
void | WinHttpCallback (DWORD code, void *info, DWORD length) |
Callback from the WinHTTP library, called when-ever something changes about the HTTP request status. | |
Data Fields | |
const std::string | uri |
URI to connect to. | |
HTTPThreadSafeCallback | callback |
Callback to send data back on. | |
const std::string | data |
Data to send, if any. | |
Private Attributes | |
const std::wstring | uri |
URI to connect to. | |
HINTERNET | connection = nullptr |
Current connection object. | |
HINTERNET | request = nullptr |
Current request object. | |
std::atomic< bool > | finished = false |
Whether we are finished with the request. | |
int | depth = 0 |
Current redirect depth we are in. | |
Single HTTP request.
Definition at line 54 of file http_curl.cpp.
|
inline |
Create a new HTTP request.
uri | the URI to connect to (https://.../..). |
callback | the callback to send data back on. |
data | the data we want to send. When non-empty, this will be a POST request, otherwise a GET request. |
Definition at line 63 of file http_curl.cpp.
References lock.
|
inline |
Destructor of the HTTP request.
Makes sure all handlers are closed, and all memory is free'd.
Definition at line 72 of file http_curl.cpp.
References lock.
NetworkHTTPRequest::NetworkHTTPRequest | ( | const std::wstring & | uri, |
HTTPCallback * | callback, | ||
const std::string & | data | ||
) |
Create a new HTTP request.
uri | the URI to connect to (https://.../..). |
callback | the callback to send data back on. |
data | the data we want to send. When non-empty, this will be a POST request, otherwise a GET request. |
Definition at line 65 of file http_winhttp.cpp.
References lock.
void NetworkHTTPRequest::Connect | ( | ) |
Start the HTTP request handling.
This is done in an async manner, so we can do other things while waiting for the HTTP request to finish. The actual receiving of the data is done in Receive().
Definition at line 213 of file http_winhttp.cpp.
References callback, connection, data, Debug, finished, HTTPThreadSafeCallback::OnFailure(), and uri.
bool NetworkHTTPRequest::Receive | ( | ) |
Poll and process the HTTP request/response.
Definition at line 266 of file http_winhttp.cpp.
References callback, Debug, finished, HTTPThreadSafeCallback::IsQueueEmpty(), and HTTPThreadSafeCallback::OnFailure().
void NetworkHTTPRequest::WinHttpCallback | ( | DWORD | code, |
void * | info, | ||
DWORD | length | ||
) |
Callback from the WinHTTP library, called when-ever something changes about the HTTP request status.
The callback needs to call some WinHttp functions for certain states, so WinHttp continues to read the request. This also allows us to abort when things go wrong, by simply not calling those functions. Comments with "Next step:" mark where WinHttp needs a call to continue.
code | The code of the event. |
info | The information about the event. |
length | The length of the information. |
Definition at line 100 of file http_winhttp.cpp.
References callback, Debug, depth, finished, HTTPThreadSafeCallback::OnFailure(), HTTPThreadSafeCallback::OnReceiveData(), and request.
HTTPThreadSafeCallback NetworkHTTPRequest::callback |
Callback to send data back on.
Definition at line 79 of file http_curl.cpp.
Referenced by Connect(), Receive(), and WinHttpCallback().
|
private |
const std::string NetworkHTTPRequest::data |
|
private |
Current redirect depth we are in.
Definition at line 37 of file http_winhttp.cpp.
Referenced by WinHttpCallback().
|
private |
Whether we are finished with the request.
Definition at line 36 of file http_winhttp.cpp.
Referenced by Connect(), Receive(), and WinHttpCallback().
|
private |
Current request object.
Definition at line 35 of file http_winhttp.cpp.
Referenced by WinHttpCallback().
const std::string NetworkHTTPRequest::uri |
|
private |
URI to connect to.
Definition at line 30 of file http_winhttp.cpp.