Wifi Duet upload: Improved some string copying.

This commit is contained in:
Vojtech Bubnik 2020-10-21 14:42:08 +02:00
parent 70e44c3e8e
commit acbf25681a
2 changed files with 6 additions and 6 deletions

View file

@ -139,7 +139,7 @@ struct Http::priv
void set_timeout_connect(long timeout); void set_timeout_connect(long timeout);
void form_add_file(const char *name, const fs::path &path, const char* filename); void form_add_file(const char *name, const fs::path &path, const char* filename);
void set_post_body(const fs::path &path); void set_post_body(const fs::path &path);
void set_post_body(const std::string body); void set_post_body(const std::string &body);
void set_put_body(const fs::path &path); void set_put_body(const fs::path &path);
std::string curl_error(CURLcode curlcode); std::string curl_error(CURLcode curlcode);
@ -155,7 +155,6 @@ Http::priv::priv(const std::string &url)
, error_buffer(CURL_ERROR_SIZE + 1, '\0') , error_buffer(CURL_ERROR_SIZE + 1, '\0')
, limit(0) , limit(0)
, cancel(false) , cancel(false)
, putFile(nullptr)
{ {
Http::tls_global_init(); Http::tls_global_init();
@ -281,14 +280,15 @@ void Http::priv::form_add_file(const char *name, const fs::path &path, const cha
} }
} }
//FIXME may throw! Is the caller aware of it?
void Http::priv::set_post_body(const fs::path &path) void Http::priv::set_post_body(const fs::path &path)
{ {
std::ifstream file(path.string()); std::ifstream file(path.string());
std::string file_content { std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>() }; std::string file_content { std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>() };
postfields = file_content; postfields = std::move(file_content);
} }
void Http::priv::set_post_body(const std::string body) void Http::priv::set_post_body(const std::string &body)
{ {
postfields = body; postfields = body;
} }
@ -488,7 +488,7 @@ Http& Http::set_post_body(const fs::path &path)
return *this; return *this;
} }
Http& Http::set_post_body(const std::string body) Http& Http::set_post_body(const std::string &body)
{ {
if (p) { p->set_post_body(body); } if (p) { p->set_post_body(body); }
return *this; return *this;

View file

@ -86,7 +86,7 @@ public:
// Set the POST request body. // Set the POST request body.
// The data is used verbatim, it is not additionally encoded in any way. // The data is used verbatim, it is not additionally encoded in any way.
// This can be used for hosts which do not support multipart requests. // This can be used for hosts which do not support multipart requests.
Http& set_post_body(const std::string body); Http& set_post_body(const std::string &body);
// Set the file contents as a PUT request body. // Set the file contents as a PUT request body.
// The data is used verbatim, it is not additionally encoded in any way. // The data is used verbatim, it is not additionally encoded in any way.