iFun Engine API  1.0.0-b2821
Great Technology for Great Games
 All Classes Files Functions Variables Typedefs Macros
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.
 

Public Member Functions

 HttpClient ()
 Constructor.
 
 ~HttpClient ()
 Destructor.
 
 DECLARE_CLASS_PTR (HttpClient)
 
CURLcode Get (const string &url)
 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...
 
size_t GetPendingRequestCount ()
 Gets the number of pending requests. More...
 
CURL * handle ()
 Returns an underlying curl handle. More...
 
CURLcode Post (const string &url, const Ptr< const string > &data)
 Initiates a POST request synchronously. More...
 
CURLcode Post (const string &url, const Json &data)
 Initiates a application/json POST request synchronously. More...
 
CURLcode Post (const string &url, const curl_httppost *data)
 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...
 
CURLcode Put (const string &url, const Ptr< const string > &data)
 Initiates a PUT request synchronously. More...
 
CURLcode Put (const string &url, const Json &data)
 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 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

CURLcode fun::HttpClient::Get ( const string &  url)
Parameters
urlstring target url. (e.g., https://www.google.com/path/)
Returns
Result in CURLcode
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.
size_t fun::HttpClient::GetPendingRequestCount ( )
Returns
the number of pending requests.
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.
CURLcode fun::HttpClient::Post ( const string &  url,
const Ptr< const string > &  data 
)
Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datapost data in string that is assumed properly encodded.
Returns
Result in CURLcode
CURLcode fun::HttpClient::Post ( const string &  url,
const Json data 
)

Content type is set to application/json.

Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datain Json.
Returns
Result in CURLcode
CURLcode fun::HttpClient::Post ( const string &  url,
const curl_httppost *  data 
)
Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datacurl_httppost pointer generated by curl_formadd().
Returns
Result in CURLcode
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.
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.
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.
CURLcode fun::HttpClient::Put ( const string &  url,
const Ptr< const string > &  data 
)
Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datapost data in string that is assumed properly encodded.
Returns
Result in CURLcode
CURLcode fun::HttpClient::Put ( const string &  url,
const Json data 
)

Content type is set to application/json.

Parameters
urlstring target url. (e.g., https://www.google.com/path/)
datain Json.
Returns
Result in CURLcode
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.
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.
const http::Response& fun::HttpClient::response ( ) const
Returns
http::Response.
void fun::HttpClient::set_verbose ( bool  on)
Parameters
ontrue/false
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.
void fun::HttpClient::UnsetHeader ( const string &  key)
Parameters
keystring HTTP header key