iFun Engine API  1.0.0-b6053
Great Technology for Great Games
Public Types | Public Member Functions | List of all members
fun::HttpClient Class Reference

Curl-based HTTP(s) client.

#include <http_client.h>

Inheritance diagram for fun::HttpClient:

Public Types

typedef function< void(const CURLcode, const http::Response &)> Handler
 Handler type for asynchronous operations.
 
typedef function< void(const CURLcode, const string &error_desc, const http::Response &)> Handler2
 

Public Member Functions

 HttpClient ()
 Constructor.
 
 ~HttpClient ()
 Destructor.
 
 DECLARE_CLASS_PTR (HttpClient)
 
CURLcode Delete (const string &url, const Ptr< const string > &data, size_t timeout_in_ms=0)
 Initiates a DELETE request synchronously. More...
 
CURLcode Delete (const string &url, const Json &data, size_t timeout_in_ms=0)
 Initiates a application/json DELETE request synchronously. More...
 
void DeleteAsync (const string &url, const Ptr< const string > &data, const Handler &handler, size_t timeout_in_ms=0)
 Initiates a DELETE request asynchronously. More...
 
void DeleteAsync (const string &url, const Json &data, const Handler &handler, size_t timeout_in_ms=0)
 Initiates a application/json DELETE request asynchronously. More...
 
void DeleteAsync2 (const string &url, const Ptr< const string > &data, const Handler2 &handler, size_t timeout_in_ms=0)
 Initiates a DELETE request asynchronously. More...
 
void DeleteAsync2 (const string &url, const Json &data, const Handler2 &handler, size_t timeout_in_ms=0)
 Initiates a application/json DELETE request asynchronously. More...
 
const stringerror_message () const
 Returns a stored error messasge. More...
 
CURLcode Get (const string &url, size_t timeout_in_ms=0)
 Initiates a GET request synchronously. More...
 
void GetAsync (const string &url, const Handler &handler, size_t timeout_in_ms=0)
 Initiates a GET request asynchronously. More...
 
void GetAsync2 (const string &url, const Handler2 &handler, size_t timeout_in_ms=0)
 Initiates a GET request asynchronously. More...
 
CURL * handle ()
 Returns an underlying curl handle. More...
 
CURLcode Post (const string &url, const Ptr< const string > &data, size_t timeout_in_ms=0)
 Initiates a POST request synchronously. More...
 
CURLcode Post (const string &url, const Json &data, size_t timeout_in_ms=0)
 Initiates a application/json POST request synchronously. More...
 
CURLcode Post (const string &url, const curl_httppost *data, size_t timeout_in_ms=0)
 Initiates a multipart form POST request synchronously. More...
 
void PostAsync (const string &url, const Ptr< const string > &data, const Handler &handler, size_t timeout_in_ms=0)
 Initiates a POST request asynchronously. More...
 
void PostAsync (const string &url, const Json &data, const Handler &handler, size_t timeout_in_ms=0)
 Initiates a application/json POST request asynchronously. More...
 
void PostAsync (const string &url, const curl_httppost *data, const Handler &handler, size_t timeout_in_ms=0)
 Initiates a multipart form POST request synchronously. More...
 
void PostAsync2 (const string &url, const Ptr< const string > &data, const Handler2 &handler, size_t timeout_in_ms=0)
 Initiates a POST request asynchronously. More...
 
void PostAsync2 (const string &url, const Json &data, const Handler2 &handler, size_t timeout_in_ms=0)
 Initiates a application/json POST request asynchronously. More...
 
void PostAsync2 (const string &url, const curl_httppost *data, const Handler2 &handler, size_t timeout_in_ms=0)
 Initiates a multipart form POST request synchronously. More...
 
CURLcode Put (const string &url, const Ptr< const string > &data, size_t timeout_in_ms=0)
 Initiates a PUT request synchronously. More...
 
CURLcode Put (const string &url, const Json &data, size_t timeout_in_ms=0)
 Initiates a application/json PUT request synchronously. More...
 
void PutAsync (const string &url, const Ptr< const string > &data, const Handler &handler, size_t timeout_in_ms=0)
 Initiates a PUT request asynchronously. More...
 
void PutAsync (const string &url, const Json &data, const Handler &handler, size_t timeout_in_ms=0)
 Initiates a application/json PUT request asynchronously. More...
 
void PutAsync2 (const string &url, const Ptr< const string > &data, const Handler2 &handler, size_t timeout_in_ms=0)
 Initiates a PUT request asynchronously. More...
 
void PutAsync2 (const string &url, const Json &data, const Handler2 &handler, size_t timeout_in_ms=0)
 Initiates a application/json PUT request asynchronously. More...
 
void ResetHeader ()
 Reset the header to the default state.
 
const http::Responseresponse () const
 Returns a stored response. More...
 
void set_verbose (bool on)
 Turns on/off verbose logging. More...
 
void SetHeader (const string &key, const string &value)
 Set HTTP header. More...
 
void UnsetHeader (const string &key)
 Removes a header item already set. More...
 

Member Function Documentation

◆ Delete() [1/2]

CURLcode fun::HttpClient::Delete ( const string url,
const Ptr< const string > &  data,
size_t  timeout_in_ms = 0 
)
Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datadelete data in string that is assumed properly encodded.
Returns
Result in CURLcode

◆ Delete() [2/2]

CURLcode fun::HttpClient::Delete ( const string url,
const Json data,
size_t  timeout_in_ms = 0 
)

Content type is set to application/json.

Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datain Json.
Returns
Result in CURLcode

◆ DeleteAsync() [1/2]

void fun::HttpClient::DeleteAsync ( const string url,
const Ptr< const string > &  data,
const Handler handler,
size_t  timeout_in_ms = 0 
)
Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datadelete data in string. The call must perform encoding.
handlerHandler functor to be invoked once operation is done.

◆ DeleteAsync() [2/2]

void fun::HttpClient::DeleteAsync ( const string url,
const Json data,
const Handler handler,
size_t  timeout_in_ms = 0 
)

Content type is set to application/json.

Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datain Json.
handlerHandler functor to be invoked once operation is done.

◆ DeleteAsync2() [1/2]

void fun::HttpClient::DeleteAsync2 ( const string url,
const Ptr< const string > &  data,
const Handler2 &  handler,
size_t  timeout_in_ms = 0 
)
Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datadelete data in string. The call must perform encoding.
handlerHandler functor to be invoked once operation is done.

◆ DeleteAsync2() [2/2]

void fun::HttpClient::DeleteAsync2 ( const string url,
const Json data,
const Handler2 &  handler,
size_t  timeout_in_ms = 0 
)

Content type is set to application/json.

Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datain Json.
handlerHandler functor to be invoked once operation is done.

◆ error_message()

const string& fun::HttpClient::error_message ( ) const
Returns
error message.

◆ Get()

CURLcode fun::HttpClient::Get ( const string url,
size_t  timeout_in_ms = 0 
)
Parameters
urlstring target url. (e.g., https://www.google.com/path/)
Returns
Result in CURLcode

◆ GetAsync()

void fun::HttpClient::GetAsync ( const string url,
const Handler handler,
size_t  timeout_in_ms = 0 
)
Parameters
urlstring target url. (e.g., https://www.google.com/path/)
handlerHandler functor to be invoked once operation is done.

◆ GetAsync2()

void fun::HttpClient::GetAsync2 ( const string url,
const Handler2 &  handler,
size_t  timeout_in_ms = 0 
)
Parameters
urlstring target url. (e.g., https://www.google.com/path/)
handlerHandler functor to be invoked once operation is done.

◆ handle()

CURL* fun::HttpClient::handle ( )

If you need to tweak curl's http option, you can pass this handle to curl_easy_setopt(...)

Returns
libcurl handle.

◆ Post() [1/3]

CURLcode fun::HttpClient::Post ( const string url,
const Ptr< const string > &  data,
size_t  timeout_in_ms = 0 
)
Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datapost data in string that is assumed properly encodded.
Returns
Result in CURLcode

◆ Post() [2/3]

CURLcode fun::HttpClient::Post ( const string url,
const Json data,
size_t  timeout_in_ms = 0 
)

Content type is set to application/json.

Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datain Json.
Returns
Result in CURLcode

◆ Post() [3/3]

CURLcode fun::HttpClient::Post ( const string url,
const curl_httppost *  data,
size_t  timeout_in_ms = 0 
)
Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datacurl_httppost pointer generated by curl_formadd().
Returns
Result in CURLcode

◆ PostAsync() [1/3]

void fun::HttpClient::PostAsync ( const string url,
const Ptr< const string > &  data,
const Handler handler,
size_t  timeout_in_ms = 0 
)
Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datapost data in string. The call must perform encoding.
handlerHandler functor to be invoked once operation is done.

◆ PostAsync() [2/3]

void fun::HttpClient::PostAsync ( const string url,
const Json data,
const Handler handler,
size_t  timeout_in_ms = 0 
)

Content type is set to application/json.

Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datain Json.
handlerHandler functor to be invoked once operation is done.

◆ PostAsync() [3/3]

void fun::HttpClient::PostAsync ( const string url,
const curl_httppost *  data,
const Handler handler,
size_t  timeout_in_ms = 0 
)

Content type is set to application/json.

Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datacurl_httppost pointer generated by curl_formadd().
handlerHandler functor to be invoked once operation is done.

◆ PostAsync2() [1/3]

void fun::HttpClient::PostAsync2 ( const string url,
const Ptr< const string > &  data,
const Handler2 &  handler,
size_t  timeout_in_ms = 0 
)
Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datapost data in string. The call must perform encoding.
handlerHandler functor to be invoked once operation is done.

◆ PostAsync2() [2/3]

void fun::HttpClient::PostAsync2 ( const string url,
const Json data,
const Handler2 &  handler,
size_t  timeout_in_ms = 0 
)

Content type is set to application/json.

Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datain Json.
handlerHandler functor to be invoked once operation is done.

◆ PostAsync2() [3/3]

void fun::HttpClient::PostAsync2 ( const string url,
const curl_httppost *  data,
const Handler2 &  handler,
size_t  timeout_in_ms = 0 
)

Content type is set to application/json.

Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datacurl_httppost pointer generated by curl_formadd().
handlerHandler functor to be invoked once operation is done.

◆ Put() [1/2]

CURLcode fun::HttpClient::Put ( const string url,
const Ptr< const string > &  data,
size_t  timeout_in_ms = 0 
)
Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datapost data in string that is assumed properly encodded.
Returns
Result in CURLcode

◆ Put() [2/2]

CURLcode fun::HttpClient::Put ( const string url,
const Json data,
size_t  timeout_in_ms = 0 
)

Content type is set to application/json.

Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datain Json.
Returns
Result in CURLcode

◆ PutAsync() [1/2]

void fun::HttpClient::PutAsync ( const string url,
const Ptr< const string > &  data,
const Handler handler,
size_t  timeout_in_ms = 0 
)
Parameters
urlstring target url. (e.g., https://www.google.com/path/)
dataput data in string. The call must perform encoding.
handlerHandler functor to be invoked once operation is done.

◆ PutAsync() [2/2]

void fun::HttpClient::PutAsync ( const string url,
const Json data,
const Handler handler,
size_t  timeout_in_ms = 0 
)

Content type is set to application/json.

Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datain Json.
handlerHandler functor to be invoked once operation is done.

◆ PutAsync2() [1/2]

void fun::HttpClient::PutAsync2 ( const string url,
const Ptr< const string > &  data,
const Handler2 &  handler,
size_t  timeout_in_ms = 0 
)
Parameters
urlstring target url. (e.g., https://www.google.com/path/)
dataput data in string. The call must perform encoding.
handlerHandler functor to be invoked once operation is done.

◆ PutAsync2() [2/2]

void fun::HttpClient::PutAsync2 ( const string url,
const Json data,
const Handler2 &  handler,
size_t  timeout_in_ms = 0 
)

Content type is set to application/json.

Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datain Json.
handlerHandler functor to be invoked once operation is done.

◆ response()

const http::Response& fun::HttpClient::response ( ) const
Returns
http::Response.

◆ set_verbose()

void fun::HttpClient::set_verbose ( bool  on)
Parameters
ontrue/false

◆ SetHeader()

void fun::HttpClient::SetHeader ( const string key,
const string value 
)

There can be multiple values with the same key.

Parameters
keystring HTTP header key.
valuestring HTTP header value.

◆ UnsetHeader()

void fun::HttpClient::UnsetHeader ( const string key)
Parameters
keystring HTTP header key