Axmol Engine 2.4.0-258ceca
Loading...
Searching...
No Matches
HttpClient Class Reference

Singleton that handles asynchronous http requests. More...

#include <HttpClient.h>

Public Member Functions

void enableCookies (const char *cookieFile)
 Enable cookie support.
 
std::string_view getCookieFilename ()
 Get the cookie filename.
 
void setSSLVerification (std::string_view caFile)
 Set root certificate path for SSL verification.
 
std::string_view getSSLVerification ()
 Get the ssl CA filename.
 
void send (HttpRequest *request)
 Add a get request to task queue.
 
void sendImmediate (HttpRequest *request)
 Immediate send a request.
 
void setTimeoutForConnect (int value)
 Set the timeout value for connecting.
 
int getTimeoutForConnect ()
 Get the timeout value for connecting.
 
void setTimeoutForRead (int value)
 Set the timeout value for reading.
 
int getTimeoutForRead ()
 Get the timeout value for reading.
 
void clearResponseAndRequestQueue ()
 Clears the pending http responses and http requests If defined, the method uses the ClearRequestPredicate and ClearResponsePredicate to check for each request/response which to delete.
 
void setClearRequestPredicate (ClearRequestPredicate predicate)
 Sets a predicate function that is going to be called to determine if we proceed each of the pending requests.
 
void setClearResponsePredicate (ClearResponsePredicate predicate)
 Sets a predicate function that is going to be called to determine if we proceed each of the pending requests.
 
void enableCookies (const char *cookieFile)
 Enable cookie support.
 
std::string_view getCookieFilename ()
 Get the cookie filename.
 
void setSSLVerification (std::string_view caFile)
 Set root certificate path for SSL verification.
 
std::string_view getSSLVerification ()
 Get the ssl CA filename.
 
void send (HttpRequest *request)
 Send http request concurrently, non-blocking.
 
void setTimeoutForConnect (int value)
 Set the timeout value for connecting.
 
int getTimeoutForConnect ()
 Get the timeout value for connecting.
 
void setTimeoutForRead (int value)
 Set the timeout value for reading.
 
int getTimeoutForRead ()
 Get the timeout value for reading.
 
void clearResponseQueue ()
 Clears the pending & finished http response.
 
void clearPendingResponseQueue ()
 Clears the pending http response.
 
void clearFinishedResponseQueue ()
 Clears the finished http response.
 
void setClearResponsePredicate (ClearResponsePredicate predicate)
 Sets a predicate function that is going to be called to determine if we proceed each of the pending requests.
 

Static Public Member Functions

static HttpClientgetInstance ()
 Get instance of HttpClient.
 
static void destroyInstance ()
 Release the instance of HttpClient.
 
static HttpClientgetInstance ()
 Get instance of HttpClient.
 
static void destroyInstance ()
 Release the instance of HttpClient.
 

Static Public Attributes

static const int RESPONSE_BUFFER_SIZE = 256
 The buffer size of _responseMessage.
 
static const int MAX_CHANNELS = 21
 How many requests could be perform concurrency.
 

Detailed Description

Singleton that handles asynchronous http requests.

Once the request completed, a callback will issued in main thread when it provided during make request.

@lua NA

Member Function Documentation

◆ getInstance() [1/2]

static HttpClient * getInstance ( )
static

Get instance of HttpClient.

Returns
the instance of HttpClient.

◆ enableCookies() [1/2]

void enableCookies ( const char * cookieFile)

Enable cookie support.

Parameters
[nullable]cookieFile the filepath of cookie file.

◆ getCookieFilename() [1/2]

std::string_view getCookieFilename ( )

Get the cookie filename.

Returns
the cookie filename

◆ setSSLVerification() [1/2]

void setSSLVerification ( std::string_view caFile)

Set root certificate path for SSL verification.

Parameters
caFilea full path of root certificate.if it is empty, SSL verification is disabled.

◆ getSSLVerification() [1/2]

std::string_view getSSLVerification ( )

Get the ssl CA filename.

Returns
the ssl CA filename

◆ send() [1/2]

void send ( HttpRequest * request)

Add a get request to task queue.

Parameters
requesta HttpRequest object, which includes url, response callback etc. please make sure request->_requestData is clear before calling "send" here.

◆ sendImmediate()

void sendImmediate ( HttpRequest * request)

Immediate send a request.

Parameters
requesta HttpRequest object, which includes url, response callback etc. please make sure request->_requestData is clear before calling "sendImmediate" here.

◆ setTimeoutForConnect() [1/2]

void setTimeoutForConnect ( int value)

Set the timeout value for connecting.

Parameters
valuethe timeout value for connecting.

◆ getTimeoutForConnect() [1/2]

int getTimeoutForConnect ( )

Get the timeout value for connecting.

Returns
int the timeout value for connecting.

◆ setTimeoutForRead() [1/2]

void setTimeoutForRead ( int value)

Set the timeout value for reading.

Parameters
valuethe timeout value for reading.

◆ getTimeoutForRead() [1/2]

int getTimeoutForRead ( )

Get the timeout value for reading.

Returns
int the timeout value for reading.

◆ setClearRequestPredicate()

void setClearRequestPredicate ( ClearRequestPredicate predicate)
inline

Sets a predicate function that is going to be called to determine if we proceed each of the pending requests.

Parameters
predicatefunction that will be called

◆ setClearResponsePredicate() [1/2]

void setClearResponsePredicate ( ClearResponsePredicate predicate)
inline

Sets a predicate function that is going to be called to determine if we proceed each of the pending requests.

Parameters
cbpredicate function that will be called

◆ getInstance() [2/2]

static HttpClient * getInstance ( )
static

Get instance of HttpClient.

Returns
the instance of HttpClient.

◆ enableCookies() [2/2]

void enableCookies ( const char * cookieFile)

Enable cookie support.

Parameters
[nullable]cookieFile the filepath of cookie file.

◆ getCookieFilename() [2/2]

std::string_view getCookieFilename ( )

Get the cookie filename.

Returns
the cookie filename

◆ setSSLVerification() [2/2]

void setSSLVerification ( std::string_view caFile)

Set root certificate path for SSL verification.

Parameters
caFilea full path of root certificate.if it is empty, SSL verification is disabled.

◆ getSSLVerification() [2/2]

std::string_view getSSLVerification ( )

Get the ssl CA filename.

Returns
the ssl CA filename

◆ send() [2/2]

void send ( HttpRequest * request)

Send http request concurrently, non-blocking.

Parameters
requesta HttpRequest object, which includes url, response callback etc. please make sure request->_requestData is clear before calling "send" here. @notes for post data a. By default will fill Content-Type: application/x-www-form-urlencoded;charset=UTF-8 b. You can specific content-type at custom header, such as: std::vector<std::string> headers = {"Content-Type: application/json;charset=UTF-8"}; request->setHeaders(headers); c. other content type, please see: https://stackoverflow.com/questions/23714383/what-are-all-the-possible-values-for-http-content-type-header

◆ setTimeoutForConnect() [2/2]

void setTimeoutForConnect ( int value)

Set the timeout value for connecting.

Parameters
valuethe timeout value for connecting.

◆ getTimeoutForConnect() [2/2]

int getTimeoutForConnect ( )

Get the timeout value for connecting.

Returns
int the timeout value for connecting.

◆ setTimeoutForRead() [2/2]

void setTimeoutForRead ( int value)

Set the timeout value for reading.

Parameters
valuethe timeout value for reading.

◆ getTimeoutForRead() [2/2]

int getTimeoutForRead ( )

Get the timeout value for reading.

Returns
int the timeout value for reading.

◆ setClearResponsePredicate() [2/2]

void setClearResponsePredicate ( ClearResponsePredicate predicate)
inline

Sets a predicate function that is going to be called to determine if we proceed each of the pending requests.

Parameters
cbpredicate function that will be called

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