diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index c933b5c21f..7817f319d4 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -28,6 +28,11 @@ #include #include +static_assert(std::is_default_constructible_v, ""); +static_assert(!std::is_copy_constructible_v, ""); +static_assert(std::is_move_constructible_v, ""); +static_assert(std::is_move_assignable_v, ""); + static int StreamReportToHttpClientReport (Stream::Report streamSendError) { switch (streamSendError) @@ -62,6 +67,54 @@ HTTPClient::~HTTPClient() } } + +HTTPClient::HTTPClient(HTTPClient&& other): _client(std::move(other._client)), + _host(std::move(other._host)), _port(std::move(other._port)), _reuse(std::move(other._reuse)), + _tcpTimeout(std::move(other._tcpTimeout)), _useHTTP10(std::move(other._useHTTP10)), + _uri(std::move(other._uri)), _protocol(std::move(other._protocol)), + _headers(std::move(other._headers)), _userAgent(std::move(other._userAgent)), + _base64Authorization(std::move(other._base64Authorization)), + _currentHeaders(std::move(other._currentHeaders)), + _headerKeysCount(std::move(other._headerKeysCount)), + _returnCode(std::move(other._returnCode)), _canReuse(std::move(other._canReuse)), + _followRedirects(std::move(other._followRedirects)), + _redirectLimit(std::move(other._redirectLimit)), _location(std::move(other._location)), + _transferEncoding(std::move(other._transferEncoding)), _payload(std::move(other._payload)) { + other._client = nullptr; + other._currentHeaders = nullptr; + other = HTTPClient(); +} + + +HTTPClient& HTTPClient::operator=(HTTPClient&& other) { + _client = std::move(other._client); + _host = std::move(other._host); + _port = std::move(other._port); + _reuse = std::move(other._reuse); + _tcpTimeout = std::move(other._tcpTimeout); + _useHTTP10 = std::move(other._useHTTP10); + _uri = std::move(other._uri); + _protocol = std::move(other._protocol); + _headers = std::move(other._headers); + _userAgent = std::move(other._userAgent); + _base64Authorization = std::move(other._base64Authorization); + _currentHeaders = std::move(other._currentHeaders); + _headerKeysCount = std::move(other._headerKeysCount); + _returnCode = std::move(other._returnCode); + _canReuse = std::move(other._canReuse); + _followRedirects = std::move(other._followRedirects); + _redirectLimit = std::move(other._redirectLimit); + _location = std::move(other._location); + _transferEncoding = std::move(other._transferEncoding); + _payload = std::move(other._payload); + + other._client = nullptr; + other._currentHeaders = nullptr; + other = HTTPClient(); + return *this; +} + + void HTTPClient::clear() { _returnCode = 0; diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h index 3605a807f3..5e68b3048e 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.h @@ -217,6 +217,9 @@ class HTTPClient const String& getString(void); static String errorToString(int error); + HTTPClient(HTTPClient&& other); + HTTPClient& operator=(HTTPClient&& other); + protected: struct RequestArgument { String key; diff --git a/tests/device/test_sw_http_client/test_sw_http_client.ino b/tests/device/test_sw_http_client/test_sw_http_client.ino index b0604291a7..ebe26fc913 100644 --- a/tests/device/test_sw_http_client/test_sw_http_client.ino +++ b/tests/device/test_sw_http_client/test_sw_http_client.ino @@ -3,6 +3,7 @@ #include #include #include +#include BS_ENV_DECLARE();