From b2f21840c6715de1de3f30efb96e4bba2bfb1a44 Mon Sep 17 00:00:00 2001 From: Benjamin Sergeant Date: Mon, 12 Oct 2020 14:03:01 -0700 Subject: [PATCH] (ws curl) Add support for --data-binary option, to set the request body. When present the request will be sent with the POST verb --- docs/CHANGELOG.md | 4 ++++ ixwebsocket/IXHttpClient.cpp | 1 - ixwebsocket/IXWebSocketVersion.h | 2 +- ws/ws.cpp | 15 ++++++++++++++- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 8b51e0dc..fa0526fb 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -2,6 +2,10 @@ All changes to this project will be documented in this file. +## [10.5.2] - 2020-10-12 + +(ws curl) Add support for --data-binary option, to set the request body. When present the request will be sent with the POST verb + ## [10.5.1] - 2020-10-09 (http client + server + ws) Add support for compressing http client requests with gzip. --compress_request argument is used in ws to enable this. The Content-Encoding is set to gzip, and decoded on the server side if present. diff --git a/ixwebsocket/IXHttpClient.cpp b/ixwebsocket/IXHttpClient.cpp index bac4f653..861d8ce4 100644 --- a/ixwebsocket/IXHttpClient.cpp +++ b/ixwebsocket/IXHttpClient.cpp @@ -588,7 +588,6 @@ namespace ix return request(url, verb, body, args); } - HttpResponsePtr HttpClient::post(const std::string& url, const HttpParameters& httpParameters, const HttpFormDataParameters& httpFormDataParameters, diff --git a/ixwebsocket/IXWebSocketVersion.h b/ixwebsocket/IXWebSocketVersion.h index 85a76afb..5a7628d5 100644 --- a/ixwebsocket/IXWebSocketVersion.h +++ b/ixwebsocket/IXWebSocketVersion.h @@ -6,4 +6,4 @@ #pragma once -#define IX_WEBSOCKET_VERSION "10.5.1" +#define IX_WEBSOCKET_VERSION "10.5.2" diff --git a/ws/ws.cpp b/ws/ws.cpp index f7d8b816..cfc0b018 100644 --- a/ws/ws.cpp +++ b/ws/ws.cpp @@ -1531,6 +1531,7 @@ namespace ix const std::string& headersData, const std::string& data, const std::string& formData, + const std::string& dataBinary, bool headersOnly, int connectTimeout, int transferTimeout, @@ -1572,10 +1573,19 @@ namespace ix { response = httpClient.head(url, args); } - else if (data.empty() && formData.empty()) + else if (data.empty() && formData.empty() && dataBinary.empty()) { response = httpClient.get(url, args); } + else if (!dataBinary.empty()) + { + std::string body = dataBinary; + if (compressRequest) + { + body = gzipCompress(dataBinary); + } + response = httpClient.request(url, "POST", body, args, 0); + } else { response = httpClient.post(url, httpParameters, httpFormDataParameters, args); @@ -2981,6 +2991,7 @@ int main(int argc, char** argv) std::string user; std::string data; std::string formData; + std::string binaryData; std::string headers; std::string output; std::string hostname("127.0.0.1"); @@ -3193,6 +3204,7 @@ int main(int argc, char** argv) httpClientApp->add_option("url", url, "Connection url")->required(); httpClientApp->add_option("-d", data, "Form data")->join(); httpClientApp->add_option("-F", formData, "Form data")->join(); + httpClientApp->add_option("--data-binary", binaryData, "Body binary data")->join(); httpClientApp->add_option("-H", headers, "Header")->join(); httpClientApp->add_option("--output", output, "Output file"); httpClientApp->add_flag("-I", headersOnly, "Send a HEAD request"); @@ -3518,6 +3530,7 @@ int main(int argc, char** argv) headers, data, formData, + binaryData, headersOnly, connectTimeOut, transferTimeout,