From fcacddbd9ff71d3e5561bb69af6b990074cb0ac9 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Mon, 3 Jun 2019 11:38:56 -0700 Subject: [PATCH] (http client) / Add DEL and PUT method, make requests and other utilities public :open_hands: --- ixwebsocket/IXHttpClient.cpp | 22 ++++++++++++++++++++++ ixwebsocket/IXHttpClient.h | 12 +++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/ixwebsocket/IXHttpClient.cpp b/ixwebsocket/IXHttpClient.cpp index 18a1ec7b..cb39f4ed 100644 --- a/ixwebsocket/IXHttpClient.cpp +++ b/ixwebsocket/IXHttpClient.cpp @@ -21,6 +21,8 @@ namespace ix const std::string HttpClient::kPost = "POST"; const std::string HttpClient::kGet = "GET"; const std::string HttpClient::kHead = "HEAD"; + const std::string HttpClient::kDel = "DEL"; + const std::string HttpClient::kPut = "PUT"; HttpClient::HttpClient() { @@ -345,6 +347,12 @@ namespace ix return request(url, kHead, std::string(), args); } + HttpResponse HttpClient::del(const std::string& url, + const HttpRequestArgs& args) + { + return request(url, kDel, std::string(), args); + } + HttpResponse HttpClient::post(const std::string& url, const HttpParameters& httpParameters, const HttpRequestArgs& args) @@ -359,6 +367,20 @@ namespace ix return request(url, kPost, body, args); } + HttpResponse HttpClient::put(const std::string& url, + const HttpParameters& httpParameters, + const HttpRequestArgs& args) + { + return request(url, kPut, serializeHttpParameters(httpParameters), args); + } + + HttpResponse HttpClient::put(const std::string& url, + const std::string& body, + const HttpRequestArgs& args) + { + return request(url, kPut, body, args); + } + std::string HttpClient::urlEncode(const std::string& value) { std::ostringstream escaped; diff --git a/ixwebsocket/IXHttpClient.h b/ixwebsocket/IXHttpClient.h index 45c0ffb1..58160423 100644 --- a/ixwebsocket/IXHttpClient.h +++ b/ixwebsocket/IXHttpClient.h @@ -71,6 +71,7 @@ namespace ix HttpResponse get(const std::string& url, const HttpRequestArgs& args); HttpResponse head(const std::string& url, const HttpRequestArgs& args); + HttpResponse del(const std::string& url, const HttpRequestArgs& args); HttpResponse post(const std::string& url, const HttpParameters& httpParameters, @@ -79,7 +80,13 @@ namespace ix const std::string& body, const HttpRequestArgs& args); - private: + HttpResponse put(const std::string& url, + const HttpParameters& httpParameters, + const HttpRequestArgs& args); + HttpResponse put(const std::string& url, + const std::string& body, + const HttpRequestArgs& args); + HttpResponse request(const std::string& url, const std::string& verb, const std::string& body, @@ -90,6 +97,7 @@ namespace ix std::string urlEncode(const std::string& value); + private: void log(const std::string& msg, const HttpRequestArgs& args); bool gzipInflate(const std::string& in, std::string& out); @@ -99,5 +107,7 @@ namespace ix const static std::string kPost; const static std::string kGet; const static std::string kHead; + const static std::string kDel; + const static std::string kPut; }; } // namespace ix