OpenTTD Source
20241121-master-g67a0fccfad
|
Single HTTP request. More...
Public Member Functions | |
NetworkHTTPRequest (const std::string &uri, HTTPCallback *callback, const std::string &data) | |
Create a new HTTP request. More... | |
~NetworkHTTPRequest () | |
Destructor of the HTTP request. More... | |
NetworkHTTPRequest (const std::wstring &uri, HTTPCallback *callback, const std::string &data) | |
Create a new HTTP request. More... | |
void | Connect () |
Start the HTTP request handling. More... | |
bool | Receive () |
Poll and process the HTTP request/response. More... | |
void | WinHttpCallback (DWORD code, void *info, DWORD length) |
Callback from the WinHTTP library, called when-ever something changes about the HTTP request status. More... | |
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 connection, Debug, 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(), and request.