mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-15 01:08:27 +00:00
Added client methods with shared pointer to Response.
This commit is contained in:
parent
d187cdef50
commit
3c8c835489
4 changed files with 72 additions and 6 deletions
19
httplib.h
19
httplib.h
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue