OpenTTD Source  20240919-master-gdf0233f4c2
NetworkHTTPRequest Class Reference

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.
 

Detailed Description

Single HTTP request.

Definition at line 54 of file http_curl.cpp.

Constructor & Destructor Documentation

◆ NetworkHTTPRequest() [1/2]

NetworkHTTPRequest::NetworkHTTPRequest ( const std::string &  uri,
HTTPCallback callback,
const std::string &  data 
)
inline

Create a new HTTP request.

Parameters
urithe URI to connect to (https://.../..).
callbackthe callback to send data back on.
datathe 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.

◆ ~NetworkHTTPRequest()

NetworkHTTPRequest::~NetworkHTTPRequest ( )
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() [2/2]

NetworkHTTPRequest::NetworkHTTPRequest ( const std::wstring &  uri,
HTTPCallback callback,
const std::string &  data 
)

Create a new HTTP request.

Parameters
urithe URI to connect to (https://.../..).
callbackthe callback to send data back on.
datathe 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.

Member Function Documentation

◆ Connect()

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.

◆ Receive()

bool NetworkHTTPRequest::Receive ( )

Poll and process the HTTP request/response.

Returns
True iff the request is done; no call to Receive() should be done after it returns true.

Definition at line 266 of file http_winhttp.cpp.

References callback, Debug, finished, HTTPThreadSafeCallback::IsQueueEmpty(), and HTTPThreadSafeCallback::OnFailure().

◆ WinHttpCallback()

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.

Parameters
codeThe code of the event.
infoThe information about the event.
lengthThe length of the information.

Definition at line 100 of file http_winhttp.cpp.

References callback, Debug, depth, finished, HTTPThreadSafeCallback::OnFailure(), and request.


The documentation for this class was generated from the following files: