Skip to content

Commit

Permalink
Allow manually setting MD5 checksum for HTTP update (#8204)
Browse files Browse the repository at this point in the history
  • Loading branch information
vlastahajek authored Sep 4, 2021
1 parent 058ce7c commit d3f16b3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 9 additions & 3 deletions libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,8 +211,14 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
DEBUG_HTTP_UPDATE("[httpUpdate] - code: %d\n", code);
DEBUG_HTTP_UPDATE("[httpUpdate] - len: %d\n", len);

if(http.hasHeader("x-MD5")) {
DEBUG_HTTP_UPDATE("[httpUpdate] - MD5: %s\n", http.header("x-MD5").c_str());
String md5;
if (_md5Sum.length()) {
md5 = _md5Sum;
} else if(http.hasHeader("x-MD5")) {
md5 = http.header("x-MD5");
}
if(md5.length()) {
DEBUG_HTTP_UPDATE("[httpUpdate] - MD5: %s\n", md5.c_str());
}

DEBUG_HTTP_UPDATE("[httpUpdate] ESP8266 info:\n");
Expand Down Expand Up @@ -298,7 +304,7 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
}
}
}
if(runUpdate(*tcp, len, http.header("x-MD5"), command)) {
if(runUpdate(*tcp, len, md5, command)) {
ret = HTTP_UPDATE_OK;
DEBUG_HTTP_UPDATE("[httpUpdate] Update ok\n");
http.end();
Expand Down
7 changes: 6 additions & 1 deletion libraries/ESP8266httpUpdate/src/ESP8266httpUpdate.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ class ESP8266HTTPUpdate
_ledOn = ledOn;
}

void setMD5sum(const String &md5Sum)
{
_md5Sum = md5Sum;
}

void setAuthorization(const String& user, const String& password);
void setAuthorization(const String& auth);

Expand Down Expand Up @@ -142,7 +147,7 @@ class ESP8266HTTPUpdate
String _user;
String _password;
String _auth;

String _md5Sum;
private:
int _httpClientTimeout;
followRedirects_t _followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS;
Expand Down

0 comments on commit d3f16b3

Please # to comment.