Kyoto Tycoon

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Static Public Member Functions | Static Public Attributes
kyototycoon::HTTPClient Class Reference

HTTP client. More...

`#include <kthttp.h>`

List of all members.

## 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.

## Detailed Description

HTTP client.

Note:
  Although all methods of this class are thread-safe, its instance does not have mutual exclusion mechanism. So, multiple threads must not share the same instance and they must use their own respective instances.

## Member Enumeration Documentation

enum kyototycoon::HTTPClient::Method

Kinds of HTTP request methods.

Enumerator:

  MGET | GET.
  MHEAD | HEAD.
  MPOST | POST.
  MPUT | PUT.
  MDELETE | DELETE.
  MUNKNOWN | unknown

## Constructor & Destructor Documentation

kyototycoon::HTTPClient::HTTPClient | ( |  | ) | `[explicit]`

Default constructor.

kyototycoon::HTTPClient::~HTTPClient | ( |  | ) |

Destructor.

## Member Function Documentation

bool kyototycoon::HTTPClient::open | ( | const std::string & | host = `""`,
|  | int32_t | port = `80`,
|  | double | timeout = `-1`
| ) |  |

Open the connection.

Parameters:

  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.

Returns:
  true on success, or false on failure.

bool kyototycoon::HTTPClient::close | ( | bool | grace = `true` | ) |

Close the connection.

Parameters:

  grace | true for graceful shutdown, or false for immediate disconnection.

Returns:
  true on success, or false on failure.

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.

Parameters:

  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.

Returns:
  the status code of the response, or -1 on failure.

Socket* kyototycoon::HTTPClient::reveal_core | ( |  | ) |

Reveal the internal TCP socket.

Returns:
  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.

Parameters:

  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.

Returns:
  the status code of the response, or -1 on failure.

## Member Data Documentation

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.