From 517855c033d0481f6241e7f23cee93c4b2890237 Mon Sep 17 00:00:00 2001 From: Paulo Date: Fri, 23 Jul 2021 20:15:50 -0300 Subject: [PATCH 1/5] Implement move operations for HTTPClient --- .../src/ESP8266HTTPClient.cpp | 48 +++++++++++++++++++ .../ESP8266HTTPClient/src/ESP8266HTTPClient.h | 3 ++ 2 files changed, 51 insertions(+) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index c933b5c21f..71aea8221a 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -62,6 +62,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; From 5b99f8d78cb3e6630045ebdfc2610e9dd01e84ca Mon Sep 17 00:00:00 2001 From: Paulo Date: Fri, 23 Jul 2021 20:19:49 -0300 Subject: [PATCH 2/5] Add test --- tests/device/test_sw_http_client/test_sw_http_client.ino | 7 +++++++ 1 file changed, 7 insertions(+) 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..d3bc444b42 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(); @@ -211,6 +212,12 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]") } } +TEST_CASE("Move constructible", "[HTTPClient]") +{ + std::optional maybe; + maybe = std::make_optional(HTTPClient()); +} + void loop() { } From 3b90e43376e19f39055997322b418a1412db87cc Mon Sep 17 00:00:00 2001 From: Paulo Date: Fri, 23 Jul 2021 20:22:26 -0300 Subject: [PATCH 3/5] Add one more test --- tests/device/test_sw_http_client/test_sw_http_client.ino | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) 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 d3bc444b42..89094cfcbc 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 @@ -214,8 +214,13 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]") TEST_CASE("Move constructible", "[HTTPClient]") { - std::optional maybe; - maybe = std::make_optional(HTTPClient()); + { + std::optional maybe; + maybe = std::make_optional(HTTPClient()); + } + { + HTTPClient http(std::move(HTTPClient())); + } } void loop() From 3b2ea1b416d6441a745364e45105be52c33639ac Mon Sep 17 00:00:00 2001 From: Paulo Date: Fri, 23 Jul 2021 20:57:44 -0300 Subject: [PATCH 4/5] Fix syntax error --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index 71aea8221a..b0011d3537 100644 --- a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp +++ b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp @@ -81,7 +81,7 @@ HTTPClient::HTTPClient(HTTPClient&& other): _client(std::move(other._client)), } -HTTPClient::HTTPClient& operator=(HTTPClient&& other) { +HTTPClient& HTTPClient::operator=(HTTPClient&& other) { _client = std::move(other._client); _host = std::move(other._host); _port = std::move(other._port); From 1577282607174c911db11905f3112070af4c647a Mon Sep 17 00:00:00 2001 From: Paulo Date: Sat, 24 Jul 2021 15:24:40 -0300 Subject: [PATCH 5/5] Move tests to use static assertions --- libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp | 5 +++++ .../test_sw_http_client/test_sw_http_client.ino | 11 ----------- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp b/libraries/ESP8266HTTPClient/src/ESP8266HTTPClient.cpp index b0011d3537..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) 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 89094cfcbc..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 @@ -212,17 +212,6 @@ TEST_CASE("HTTPS GET request", "[HTTPClient]") } } -TEST_CASE("Move constructible", "[HTTPClient]") -{ - { - std::optional maybe; - maybe = std::make_optional(HTTPClient()); - } - { - HTTPClient http(std::move(HTTPClient())); - } -} - void loop() { }