Kyoto Tycoon
|
HTTP client. More...
#include <kthttp.h>
Public Types | |
enum | Method { MGET, MHEAD, MPOST, MPUT, MDELETE, MUNKNOWN } |
Kinds of HTTP request methods. More... | |
Public Member Functions | |
HTTPClient () | |
Default constructor. | |
~HTTPClient () | |
Destructor. | |
bool | open (const std::string &host="", int32_t port=80, double timeout=-1) |
Open the connection. | |
bool | close (bool grace=true) |
Close the connection. | |
int32_t | fetch (const std::string &pathquery, Method method=MGET, std::string *resbody=NULL, std::map< std::string, std::string > *resheads=NULL, const std::string *reqbody=NULL, const std::map< std::string, std::string > *reqheads=NULL) |
Fetch a resource. | |
Socket * | reveal_core () |
Reveal the internal TCP socket. | |
Static Public Member Functions | |
static int32_t | fetch_once (const std::string &url, Method method=MGET, std::string *resbody=NULL, std::map< std::string, std::string > *resheads=NULL, const std::string *reqbody=NULL, const std::map< std::string, std::string > *reqheads=NULL, double timeout=-1) |
Fetch a resource at once. | |
Static Public Attributes | |
static const int32_t | LINEBUFSIZ = 8192 |
The size for a line buffer. | |
static const int32_t | RECVMAXSIZ = 1 << 28 |
The maximum size of received data. |
HTTP client.
kyototycoon::HTTPClient::HTTPClient | ( | ) | [explicit] |
Default constructor.
Destructor.
bool kyototycoon::HTTPClient::open | ( | const std::string & | host = "" , |
int32_t | port = 80 , |
||
double | timeout = -1 |
||
) |
Open the connection.
host | the name or the address of the server. If it is an empty string, the local host is specified. |
port | the port numger of the server. |
timeout | the timeout of each operation in seconds. If it is not more than 0, no timeout is specified. |
bool kyototycoon::HTTPClient::close | ( | bool | grace = true | ) |
Close the connection.
grace | true for graceful shutdown, or false for immediate disconnection. |
int32_t kyototycoon::HTTPClient::fetch | ( | const std::string & | pathquery, |
Method | method = MGET , |
||
std::string * | resbody = NULL , |
||
std::map< std::string, std::string > * | resheads = NULL , |
||
const std::string * | reqbody = NULL , |
||
const std::map< std::string, std::string > * | reqheads = NULL |
||
) |
Fetch a resource.
pathquery | the path and the query string of the resource. |
method | the kind of the request methods. |
resbody | a string to contain the entity body of the response. If it is NULL, it is ignored. |
resheads | a string map to contain the headers of the response. If it is NULL, it is ignored. Header names are converted into lower cases. The empty key means the request-line. |
reqbody | a string which contains the entity body of the request. If it is NULL, it is ignored. |
reqheads | a string map which contains the headers of the request. If it is NULL, it is ignored. |
Reveal the internal TCP socket.
static int32_t kyototycoon::HTTPClient::fetch_once | ( | const std::string & | url, |
Method | method = MGET , |
||
std::string * | resbody = NULL , |
||
std::map< std::string, std::string > * | resheads = NULL , |
||
const std::string * | reqbody = NULL , |
||
const std::map< std::string, std::string > * | reqheads = NULL , |
||
double | timeout = -1 |
||
) | [static] |
Fetch a resource at once.
url | the URL of the resource. |
method | the kind of the request methods. |
resbody | a string to contain the entity body of the response. If it is NULL, it is ignored. |
resheads | a string map to contain the headers of the response. If it is NULL, it is ignored. Header names are converted into lower cases. The empty key means the request-line. |
reqbody | a string which contains the entity body of the request. If it is NULL, it is ignored. |
reqheads | a string map which contains the headers of the request. If it is NULL, it is ignored. |
timeout | the timeout of each operation in seconds. If it is not more than 0, no timeout is specified. |
const int32_t kyototycoon::HTTPClient::LINEBUFSIZ = 8192 [static] |
The size for a line buffer.
const int32_t kyototycoon::HTTPClient::RECVMAXSIZ = 1 << 28 [static] |
The maximum size of received data.