From 05e4ef552fa69140cefe8da5669799c8c4bf21f3 Mon Sep 17 00:00:00 2001 From: Mohammed Noureldin Date: Thu, 18 Mar 2021 03:13:20 +0100 Subject: [PATCH 1/3] Allow passing custom HTTPClient This enables customizing HTTP headers and adds some extra flexibility. --- libraries/HTTPUpdate/src/HTTPUpdate.cpp | 19 +++++++++++++++++++ libraries/HTTPUpdate/src/HTTPUpdate.h | 4 ++++ 2 files changed, 23 insertions(+) diff --git a/libraries/HTTPUpdate/src/HTTPUpdate.cpp b/libraries/HTTPUpdate/src/HTTPUpdate.cpp index f4c3d250fa7..fdf2bc6d289 100644 --- a/libraries/HTTPUpdate/src/HTTPUpdate.cpp +++ b/libraries/HTTPUpdate/src/HTTPUpdate.cpp @@ -56,6 +56,15 @@ HTTPUpdateResult HTTPUpdate::update(WiFiClient& client, const String& url, const return handleUpdate(http, currentVersion, false); } +HTTPUpdateResult HTTPUpdate::updateSpiffs(WiFiClient& client, HTTPClient& httpClient, const String& url, const String& currentVersion) +{ + if(!httpClient.begin(client, url)) + { + return HTTP_UPDATE_FAILED; + } + return handleUpdate(httpClient, currentVersion, true); +} + HTTPUpdateResult HTTPUpdate::updateSpiffs(WiFiClient& client, const String& url, const String& currentVersion) { HTTPClient http; @@ -66,6 +75,16 @@ HTTPUpdateResult HTTPUpdate::updateSpiffs(WiFiClient& client, const String& url, return handleUpdate(http, currentVersion, true); } +HTTPUpdateResult HTTPUpdate::update(WiFiClient& client, HTTPClient& httpClient, const String& host, uint16_t port, const String& uri, + const String& currentVersion) +{ + if(!httpClient.begin(client, host, port, uri)) + { + return HTTP_UPDATE_FAILED; + } + return handleUpdate(httpClient, currentVersion, false); +} + HTTPUpdateResult HTTPUpdate::update(WiFiClient& client, const String& host, uint16_t port, const String& uri, const String& currentVersion) { diff --git a/libraries/HTTPUpdate/src/HTTPUpdate.h b/libraries/HTTPUpdate/src/HTTPUpdate.h index f126cba0639..70b6a641d84 100644 --- a/libraries/HTTPUpdate/src/HTTPUpdate.h +++ b/libraries/HTTPUpdate/src/HTTPUpdate.h @@ -77,6 +77,10 @@ class HTTPUpdate t_httpUpdate_return updateSpiffs(WiFiClient& client, const String& url, const String& currentVersion = ""); + t_httpUpdate_return update(WiFiClient& client, HTTPClient& httpClient, const String& host, uint16_t port, const String& uri = "/", + const String& currentVersion = ""); + + t_httpUpdate_return updateSpiffs(WiFiClient &client, HTTPClient &httpClient, const String &url, const String ¤tVersion = ""); int getLastError(void); String getLastErrorString(void); From 7f05cb3fd3c8797b1c5a14f7ff154c788aa61954 Mon Sep 17 00:00:00 2001 From: Mohammed Noureldin Date: Thu, 18 Mar 2021 10:01:27 +0100 Subject: [PATCH 2/3] Remove WiFiClient when passing HTTPClient to HTTPUpdate --- libraries/HTTPUpdate/src/HTTPUpdate.cpp | 12 ++---------- libraries/HTTPUpdate/src/HTTPUpdate.h | 4 ++-- 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/libraries/HTTPUpdate/src/HTTPUpdate.cpp b/libraries/HTTPUpdate/src/HTTPUpdate.cpp index 70825493bb7..ea90beb2676 100644 --- a/libraries/HTTPUpdate/src/HTTPUpdate.cpp +++ b/libraries/HTTPUpdate/src/HTTPUpdate.cpp @@ -58,12 +58,8 @@ HTTPUpdateResult HTTPUpdate::update(WiFiClient& client, const String& url, const return handleUpdate(http, currentVersion, false); } -HTTPUpdateResult HTTPUpdate::updateSpiffs(WiFiClient& client, HTTPClient& httpClient, const String& url, const String& currentVersion) +HTTPUpdateResult HTTPUpdate::updateSpiffs(HTTPClient& httpClient, const String& url, const String& currentVersion) { - if(!httpClient.begin(client, url)) - { - return HTTP_UPDATE_FAILED; - } return handleUpdate(httpClient, currentVersion, true); } @@ -77,13 +73,9 @@ HTTPUpdateResult HTTPUpdate::updateSpiffs(WiFiClient& client, const String& url, return handleUpdate(http, currentVersion, true); } -HTTPUpdateResult HTTPUpdate::update(WiFiClient& client, HTTPClient& httpClient, const String& host, uint16_t port, const String& uri, +HTTPUpdateResult HTTPUpdate::update(HTTPClient& httpClient, const String& host, uint16_t port, const String& uri, const String& currentVersion) { - if(!httpClient.begin(client, host, port, uri)) - { - return HTTP_UPDATE_FAILED; - } return handleUpdate(httpClient, currentVersion, false); } diff --git a/libraries/HTTPUpdate/src/HTTPUpdate.h b/libraries/HTTPUpdate/src/HTTPUpdate.h index 91e96050034..9ec6c8767dc 100644 --- a/libraries/HTTPUpdate/src/HTTPUpdate.h +++ b/libraries/HTTPUpdate/src/HTTPUpdate.h @@ -86,10 +86,10 @@ class HTTPUpdate t_httpUpdate_return updateSpiffs(WiFiClient& client, const String& url, const String& currentVersion = ""); - t_httpUpdate_return update(WiFiClient& client, HTTPClient& httpClient, const String& host, uint16_t port, const String& uri = "/", + t_httpUpdate_return update(HTTPClient& httpClient, const String& host, uint16_t port, const String& uri = "/", const String& currentVersion = ""); - t_httpUpdate_return updateSpiffs(WiFiClient &client, HTTPClient &httpClient, const String &url, const String ¤tVersion = ""); + t_httpUpdate_return updateSpiffs(HTTPClient &httpClient, const String &url, const String ¤tVersion = ""); int getLastError(void); String getLastErrorString(void); From 600a67cd02445570e0dfb59d1f6c964b9d436b94 Mon Sep 17 00:00:00 2001 From: Mohammed Noureldin Date: Thu, 18 Mar 2021 11:40:15 +0100 Subject: [PATCH 3/3] Remove redundant arguments from HTTPUpdate::update These arguments are not required when passing the HTTPClient instead of WiFiClient. --- libraries/HTTPUpdate/src/HTTPUpdate.cpp | 4 ++-- libraries/HTTPUpdate/src/HTTPUpdate.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libraries/HTTPUpdate/src/HTTPUpdate.cpp b/libraries/HTTPUpdate/src/HTTPUpdate.cpp index ea90beb2676..d5c65f2006c 100644 --- a/libraries/HTTPUpdate/src/HTTPUpdate.cpp +++ b/libraries/HTTPUpdate/src/HTTPUpdate.cpp @@ -58,7 +58,7 @@ HTTPUpdateResult HTTPUpdate::update(WiFiClient& client, const String& url, const return handleUpdate(http, currentVersion, false); } -HTTPUpdateResult HTTPUpdate::updateSpiffs(HTTPClient& httpClient, const String& url, const String& currentVersion) +HTTPUpdateResult HTTPUpdate::updateSpiffs(HTTPClient& httpClient, const String& currentVersion) { return handleUpdate(httpClient, currentVersion, true); } @@ -73,7 +73,7 @@ HTTPUpdateResult HTTPUpdate::updateSpiffs(WiFiClient& client, const String& url, return handleUpdate(http, currentVersion, true); } -HTTPUpdateResult HTTPUpdate::update(HTTPClient& httpClient, const String& host, uint16_t port, const String& uri, +HTTPUpdateResult HTTPUpdate::update(HTTPClient& httpClient, const String& currentVersion) { return handleUpdate(httpClient, currentVersion, false); diff --git a/libraries/HTTPUpdate/src/HTTPUpdate.h b/libraries/HTTPUpdate/src/HTTPUpdate.h index 9ec6c8767dc..af404e71876 100644 --- a/libraries/HTTPUpdate/src/HTTPUpdate.h +++ b/libraries/HTTPUpdate/src/HTTPUpdate.h @@ -86,10 +86,10 @@ class HTTPUpdate t_httpUpdate_return updateSpiffs(WiFiClient& client, const String& url, const String& currentVersion = ""); - t_httpUpdate_return update(HTTPClient& httpClient, const String& host, uint16_t port, const String& uri = "/", + t_httpUpdate_return update(HTTPClient& httpClient, const String& currentVersion = ""); - t_httpUpdate_return updateSpiffs(HTTPClient &httpClient, const String &url, const String ¤tVersion = ""); + t_httpUpdate_return updateSpiffs(HTTPClient &httpClient, const String ¤tVersion = ""); int getLastError(void); String getLastErrorString(void);