Skip to content

Commit ddddd9b

Browse files
committed
feat: adding possibility to manually set MD5 checksum for HTTP update
1 parent b63f947 commit ddddd9b

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

libraries/HTTPUpdate/src/HTTPUpdate.cpp

+9-3
Original file line numberDiff line numberDiff line change
@@ -240,8 +240,14 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
240240
log_d(" - code: %d\n", code);
241241
log_d(" - len: %d\n", len);
242242

243-
if(http.hasHeader("x-MD5")) {
244-
log_d(" - MD5: %s\n", http.header("x-MD5").c_str());
243+
String md5;
244+
if (_md5Sum.length()) {
245+
md5 = _md5Sum;
246+
} else if(http.hasHeader("x-MD5")) {
247+
md5 = http.header("x-MD5");
248+
}
249+
if(md5.length()) {
250+
log_d(" - MD5: %s\n",md5.c_str());
245251
}
246252

247253
log_d("ESP32 info:\n");
@@ -338,7 +344,7 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
338344
}
339345
*/
340346
}
341-
if(runUpdate(*tcp, len, http.header("x-MD5"), command)) {
347+
if(runUpdate(*tcp, len, md5, command)) {
342348
ret = HTTP_UPDATE_OK;
343349
log_d("Update ok\n");
344350
http.end();

libraries/HTTPUpdate/src/HTTPUpdate.h

+6
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,11 @@ class HTTPUpdate
8484
_ledOn = ledOn;
8585
}
8686

87+
void setMD5sum(const String &md5Sum)
88+
{
89+
_md5Sum = md5Sum;
90+
}
91+
8792
t_httpUpdate_return update(WiFiClient& client, const String& url, const String& currentVersion = "");
8893

8994
t_httpUpdate_return update(WiFiClient& client, const String& host, uint16_t port, const String& uri = "/",
@@ -121,6 +126,7 @@ class HTTPUpdate
121126
private:
122127
int _httpClientTimeout;
123128
followRedirects_t _followRedirects;
129+
String _md5Sum;
124130

125131
// Callbacks
126132
HTTPUpdateStartCB _cbStart;

0 commit comments

Comments
 (0)