diff --git a/src/network/core/http.h b/src/network/core/http.h index dfeadb7596..2a6d1614af 100644 --- a/src/network/core/http.h +++ b/src/network/core/http.h @@ -55,7 +55,7 @@ public: * @param callback the callback to send data back on. * @param data the data we want to send. When non-empty, this will be a POST request, otherwise a GET request. */ - static void Connect(const std::string &uri, HTTPCallback *callback, const std::string data = ""); + static void Connect(std::string_view uri, HTTPCallback *callback, std::string &&data = ""); /** * Do the receiving for all HTTP connections. diff --git a/src/network/core/http_curl.cpp b/src/network/core/http_curl.cpp index 334d0fd6d0..efe399ced8 100644 --- a/src/network/core/http_curl.cpp +++ b/src/network/core/http_curl.cpp @@ -60,10 +60,10 @@ public: * @param callback the callback to send data back on. * @param data the data we want to send. When non-empty, this will be a POST request, otherwise a GET request. */ - NetworkHTTPRequest(const std::string &uri, HTTPCallback *callback, const std::string &data) : + NetworkHTTPRequest(std::string_view uri, HTTPCallback *callback, std::string &&data) : uri(uri), callback(callback), - data(data) + data(std::move(data)) { std::lock_guard lock(_new_http_callback_mutex); _new_http_callbacks.push_back(&this->callback); @@ -90,7 +90,7 @@ static std::string _http_ca_file = ""; static std::string _http_ca_path = ""; #endif /* UNIX */ -/* static */ void NetworkHTTPSocketHandler::Connect(const std::string &uri, HTTPCallback *callback, const std::string data) +/* static */ void NetworkHTTPSocketHandler::Connect(std::string_view uri, HTTPCallback *callback, std::string &&data) { #if defined(UNIX) if (_http_ca_file.empty() && _http_ca_path.empty()) { @@ -100,7 +100,7 @@ static std::string _http_ca_path = ""; #endif /* UNIX */ std::lock_guard lock(_http_mutex); - _http_requests.push(std::make_unique(uri, callback, data)); + _http_requests.push(std::make_unique(uri, callback, std::move(data))); _http_cv.notify_one(); } diff --git a/src/network/core/http_none.cpp b/src/network/core/http_none.cpp index 822c71f01c..2c3816834b 100644 --- a/src/network/core/http_none.cpp +++ b/src/network/core/http_none.cpp @@ -18,7 +18,7 @@ #include "../../safeguards.h" -/* static */ void NetworkHTTPSocketHandler::Connect(const std::string &, HTTPCallback *callback, const std::string) +/* static */ void NetworkHTTPSocketHandler::Connect(std::string_view, HTTPCallback *callback, std::string&&) { /* No valid HTTP backend was compiled in, so we fail all HTTP requests. */ callback->OnFailure(); diff --git a/src/network/core/http_winhttp.cpp b/src/network/core/http_winhttp.cpp index 11bf67d6f7..1c55562e7b 100644 --- a/src/network/core/http_winhttp.cpp +++ b/src/network/core/http_winhttp.cpp @@ -37,7 +37,7 @@ private: int depth = 0; ///< Current redirect depth we are in. public: - NetworkHTTPRequest(const std::wstring &uri, HTTPCallback *callback, const std::string &data); + NetworkHTTPRequest(std::wstring &&uri, HTTPCallback *callback, std::string &&data); ~NetworkHTTPRequest(); @@ -62,10 +62,10 @@ static std::mutex _new_http_callback_mutex; * @param callback the callback to send data back on. * @param data the data we want to send. When non-empty, this will be a POST request, otherwise a GET request. */ -NetworkHTTPRequest::NetworkHTTPRequest(const std::wstring &uri, HTTPCallback *callback, const std::string &data) : - uri(uri), +NetworkHTTPRequest::NetworkHTTPRequest(std::wstring &&uri, HTTPCallback *callback, std::string &&data) : + uri(std::move(uri)), callback(callback), - data(data) + data(std::move(data)) { std::lock_guard lock(_new_http_callback_mutex); _new_http_callbacks.push_back(&this->callback); @@ -291,9 +291,9 @@ NetworkHTTPRequest::~NetworkHTTPRequest() _http_callbacks.erase(std::remove(_http_callbacks.begin(), _http_callbacks.end(), &this->callback), _http_callbacks.end()); } -/* static */ void NetworkHTTPSocketHandler::Connect(const std::string &uri, HTTPCallback *callback, const std::string data) +/* static */ void NetworkHTTPSocketHandler::Connect(std::string_view uri, HTTPCallback *callback, std::string &&data) { - auto request = new NetworkHTTPRequest(std::wstring(uri.begin(), uri.end()), callback, data); + auto request = new NetworkHTTPRequest(std::wstring(uri.begin(), uri.end()), callback, std::move(data)); request->Connect(); std::lock_guard lock(_new_http_requests_mutex);