From 204688464ea58d2c0867f7c4027ddfa1a0511342 Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Thu, 17 Nov 2022 02:47:00 +0100 Subject: [PATCH] rename Http:put() to Http:post() and add a separate Http:put() --- winixd/utils/http.cpp | 46 ++++++++++++++++++++++++++++++++++++++----- winixd/utils/http.h | 6 ++++++ 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/winixd/utils/http.cpp b/winixd/utils/http.cpp index fd083df..57b951f 100644 --- a/winixd/utils/http.cpp +++ b/winixd/utils/http.cpp @@ -73,6 +73,7 @@ Http & Http::begin() debug_info = nullptr; follow_location = true; verify_ssl_cert = true; + use_post_method = true; return *this; } @@ -281,7 +282,7 @@ bool Http::get(const pt::WTextStream & url, pt::WTextStream & out, bool clear_st } -bool Http::put(const wchar_t * url, const std::string & in, pt::WTextStream & out, bool clear_stream) +bool Http::post_put(const wchar_t * url, const std::string & in, pt::WTextStream & out, bool clear_stream) { std::string url_ascii; pt::TextStream out_stream; @@ -300,9 +301,40 @@ bool Http::put(const wchar_t * url, const std::string & in, pt::WTextStream & ou } +bool Http::post(const wchar_t * url, const std::string & in, pt::WTextStream & out, bool clear_stream) +{ + use_post_method = true; + return post_put(url, in, out, clear_stream); +} + + +bool Http::post(const std::wstring & url, const std::string & in, pt::WTextStream & out, bool clear_stream) +{ + use_post_method = true; + return post_put(url.c_str(), in, out, clear_stream); +} + + +bool Http::post(const wchar_t * url, pt::WTextStream & in, pt::WTextStream & out, bool clear_stream) +{ + std::string in_ascii; + in.to_str(in_ascii); + use_post_method = true; + return post_put(url, in_ascii, out, clear_stream); +} + + +bool Http::put(const wchar_t * url, const std::string & in, pt::WTextStream & out, bool clear_stream) +{ + use_post_method = false; + return post_put(url, in, out, clear_stream); +} + + bool Http::put(const std::wstring & url, const std::string & in, pt::WTextStream & out, bool clear_stream) { - return put(url.c_str(), in, out, clear_stream); + use_post_method = false; + return post_put(url.c_str(), in, out, clear_stream); } @@ -310,8 +342,8 @@ bool Http::put(const wchar_t * url, pt::WTextStream & in, pt::WTextStream & out, { std::string in_ascii; in.to_str(in_ascii); - - return put(url, in_ascii, out, clear_stream); + use_post_method = false; + return post_put(url, in_ascii, out, clear_stream); } @@ -488,7 +520,11 @@ bool Http::fetch_internal(const char * url, const std::string * in, pt::TextStre curl_easy_setopt(curl, CURLOPT_READDATA, this); curl_easy_setopt(curl, CURLOPT_SEEKFUNCTION, fetch_seek_function); curl_easy_setopt(curl, CURLOPT_SEEKDATA, this); - curl_easy_setopt(curl, CURLOPT_POST, 1); + + if( use_post_method ) + curl_easy_setopt(curl, CURLOPT_POST, 1); + else + curl_easy_setopt(curl, CURLOPT_PUT, 1); curl_off_t size = read_function_input->size(); curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, size); diff --git a/winixd/utils/http.h b/winixd/utils/http.h index 4234622..99b5817 100644 --- a/winixd/utils/http.h +++ b/winixd/utils/http.h @@ -165,6 +165,10 @@ public: bool get(const std::wstring & url, pt::WTextStream & out, bool clear_stream = true); bool get(const pt::WTextStream & url, pt::WTextStream & out, bool clear_stream = true); + bool post(const wchar_t * url, const std::string & in, pt::WTextStream & out, bool clear_stream = true); + bool post(const std::wstring & url, const std::string & in, pt::WTextStream & out, bool clear_stream = true); + bool post(const wchar_t * url, pt::WTextStream & in, pt::WTextStream & out, bool clear_stream = true); + bool put(const wchar_t * url, const std::string & in, pt::WTextStream & out, bool clear_stream = true); bool put(const std::wstring & url, const std::string & in, pt::WTextStream & out, bool clear_stream = true); bool put(const wchar_t * url, pt::WTextStream & in, pt::WTextStream & out, bool clear_stream = true); @@ -196,6 +200,7 @@ private: pt::Space * debug_info; bool follow_location; bool verify_ssl_cert; + bool use_post_method; /* if false then use put method - used only when calling post() or put() methods */ std::wstring temp_header; std::string temp_header_ascii; @@ -203,6 +208,7 @@ private: std::wstring temp_header_value; std::string temp_header_value_ascii; + bool post_put(const wchar_t * url, const std::string & in, pt::WTextStream & out, bool clear_stream); bool fetch_internal(const char * url, const std::string * in, pt::TextStream & out); static size_t fetch_read_function(char * ptr, size_t size, size_t nmemb, void * userdata); static int fetch_seek_set(Http * http, curl_off_t offset);