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
This commit is contained in:
parent
79e971cb76
commit
5e45ad3417
|
@ -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_input = in; // can be null
|
||||||
read_function_index = 0;
|
read_function_index = 0;
|
||||||
|
|
||||||
put_method(method);
|
put_method(method, in);
|
||||||
|
|
||||||
if( read_function_input )
|
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)
|
switch(method)
|
||||||
{
|
{
|
||||||
case Method::method_post:
|
case Method::method_post:
|
||||||
curl_easy_setopt(curl, CURLOPT_POST, 1);
|
curl_easy_setopt(curl, CURLOPT_POST, 1L);
|
||||||
break;
|
|
||||||
|
if( in )
|
||||||
|
curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE_LARGE, in->size());
|
||||||
|
|
||||||
case Method::method_put:
|
|
||||||
curl_easy_setopt(curl, CURLOPT_PUT, 1);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Method::method_patch:
|
case Method::method_patch:
|
||||||
|
|
|
@ -346,7 +346,7 @@ private:
|
||||||
std::string temp_header_value_ascii;
|
std::string temp_header_value_ascii;
|
||||||
|
|
||||||
bool fetch_internal(Method method, const char * url, const std::string * in, pt::TextStream & out);
|
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 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_set(Http * http, curl_off_t offset);
|
||||||
static int fetch_seek_cur(Http * http, curl_off_t offset);
|
static int fetch_seek_cur(Http * http, curl_off_t offset);
|
||||||
|
|
Loading…
Reference in New Issue