From 5e45ad3417febcb64279560f736e9a07b10dcf9a Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Tue, 26 Sep 2023 23:02:34 +0200 Subject: [PATCH] fix(Http): send body content for PATCH, DELETE and OPTIONS methods if exists while here: - use CURLOPT_UPLOAD instead of CURLOPT_PUT as the latter is depracated --- winixd/utils/http.cpp | 25 +++++++++++++++++-------- winixd/utils/http.h | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/winixd/utils/http.cpp b/winixd/utils/http.cpp index 5825c4a..51e83fb 100644 --- a/winixd/utils/http.cpp +++ b/winixd/utils/http.cpp @@ -521,7 +521,7 @@ void Http::add_additional_space_headers() header << value->value.value_wstring; } else - if( value->is_str() ) + if( value->is_str() ) { header << value->value.value_string; } @@ -670,7 +670,7 @@ bool Http::fetch_internal(Method method, const char * url, const std::string * i read_function_input = in; // can be null read_function_index = 0; - put_method(method); + put_method(method, in); if( read_function_input ) { @@ -784,18 +784,27 @@ bool Http::fetch_internal(Method method, const char * url, const std::string * i } -void Http::put_method(Method & method) +// we don't put 'get' here +void Http::put_method(Method & method, const std::string * in) { - // we don't put 'get' here + if( method == Method::method_put || method == Method::method_patch || + method == Method::method_delete || method == Method::method_options ) + { + if( in ) + { + curl_easy_setopt(curl, CURLOPT_UPLOAD, 1L); + curl_easy_setopt(curl, CURLOPT_INFILESIZE_LARGE, in->size()); + } + } switch(method) { case Method::method_post: - curl_easy_setopt(curl, CURLOPT_POST, 1); - break; + curl_easy_setopt(curl, CURLOPT_POST, 1L); + + if( in ) + curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, in->size()); - case Method::method_put: - curl_easy_setopt(curl, CURLOPT_PUT, 1); break; case Method::method_patch: diff --git a/winixd/utils/http.h b/winixd/utils/http.h index ed0842c..448d0f1 100644 --- a/winixd/utils/http.h +++ b/winixd/utils/http.h @@ -346,7 +346,7 @@ private: std::string temp_header_value_ascii; bool fetch_internal(Method method, const char * url, const std::string * in, pt::TextStream & out); - void put_method(Method & method); + void put_method(Method & method, const std::string * in); 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); static int fetch_seek_cur(Http * http, curl_off_t offset);