From 0596a2ac86f59e26ae04cad24490392a9732a297 Mon Sep 17 00:00:00 2001 From: Jeroen88 Date: Thu, 6 Dec 2018 18:50:53 +0100 Subject: [PATCH] Abort update if http.begin() returns false. Fix a typo in httpUpdate.ino (#2156) --- .../HTTPUpdate/examples/httpUpdate/httpUpdate.ino | 2 +- libraries/HTTPUpdate/src/HTTPUpdate.cpp | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/libraries/HTTPUpdate/examples/httpUpdate/httpUpdate.ino b/libraries/HTTPUpdate/examples/httpUpdate/httpUpdate.ino index c9018cd4..f646be04 100644 --- a/libraries/HTTPUpdate/examples/httpUpdate/httpUpdate.ino +++ b/libraries/HTTPUpdate/examples/httpUpdate/httpUpdate.ino @@ -56,7 +56,7 @@ void loop() { switch (ret) { case HTTP_UPDATE_FAILED: - Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str()); + Serial.printf("HTTP_UPDATE_FAILED Error (%d): %s\n", httpUpdate.getLastError(), httpUpdate.getLastErrorString().c_str()); break; case HTTP_UPDATE_NO_UPDATES: diff --git a/libraries/HTTPUpdate/src/HTTPUpdate.cpp b/libraries/HTTPUpdate/src/HTTPUpdate.cpp index c3a04cc8..af263936 100644 --- a/libraries/HTTPUpdate/src/HTTPUpdate.cpp +++ b/libraries/HTTPUpdate/src/HTTPUpdate.cpp @@ -49,14 +49,20 @@ HTTPUpdate::~HTTPUpdate(void) HTTPUpdateResult HTTPUpdate::update(WiFiClient& client, const String& url, const String& currentVersion) { HTTPClient http; - http.begin(client, url); + if(!http.begin(client, url)) + { + return HTTP_UPDATE_FAILED; + } return handleUpdate(http, currentVersion, false); } HTTPUpdateResult HTTPUpdate::updateSpiffs(WiFiClient& client, const String& url, const String& currentVersion) { HTTPClient http; - http.begin(client, url); + if(!http.begin(client, url)) + { + return HTTP_UPDATE_FAILED; + } return handleUpdate(http, currentVersion, true); } @@ -64,7 +70,10 @@ HTTPUpdateResult HTTPUpdate::update(WiFiClient& client, const String& host, uint const String& currentVersion) { HTTPClient http; - http.begin(client, host, port, uri); + if(!http.begin(client, host, port, uri)) + { + return HTTP_UPDATE_FAILED; + } return handleUpdate(http, currentVersion, false); }