Added client methods with shared pointer to Response.

This commit is contained in:
yhirose 2012-10-04 01:18:18 -04:00
parent d187cdef50
commit 3c8c835489
4 changed files with 72 additions and 6 deletions

View file

@ -126,6 +126,9 @@ public:
bool post(const char* url, const std::string& body, const char* content_type, Response& res);
bool send(const Request& req, Response& res);
std::shared_ptr<Response> get(const char* url);
std::shared_ptr<Response> post(const char* url, const std::string& body, const char* content_type);
private:
bool read_response_line(FILE* fp, Response& res);
@ -634,7 +637,8 @@ inline bool Client::get(const char* url, Response& res)
return send(req, res);
}
inline bool Client::post(const char* url, const std::string& body, const char* content_type, Response& res)
inline bool Client::post(
const char* url, const std::string& body, const char* content_type, Response& res)
{
Request req;
req.method = "POST";
@ -670,6 +674,19 @@ inline bool Client::send(const Request& req, Response& res)
return true;
}
inline std::shared_ptr<Response> Client::get(const char* url)
{
auto res = std::make_shared<Response>();
return get(url, *res) ? res : nullptr;
}
inline std::shared_ptr<Response> Client::post(
const char* url, const std::string& body, const char* content_type)
{
auto res = std::make_shared<Response>();
return post(url, body, content_type, *res) ? res : nullptr;
}
} // namespace httplib
#endif