Skip to content

Commit 62ca5dd

Browse files
committed
feat: adding possibility to manually set MD5 checksum for HTTP update
1 parent 0d84018 commit 62ca5dd

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

libraries/HTTPUpdate/src/HTTPUpdate.cpp

+11-5
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@
3333
// To do extern "C" uint32_t _SPIFFS_end;
3434

3535
HTTPUpdate::HTTPUpdate(void)
36-
: _httpClientTimeout(8000), _ledPin(-1)
36+
: HTTPUpdate(8000)
3737
{
38-
_followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS;
3938
}
4039

4140
HTTPUpdate::HTTPUpdate(int httpClientTimeout)
4241
: _httpClientTimeout(httpClientTimeout), _ledPin(-1)
4342
{
4443
_followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS;
44+
_md5Sum = String();
4545
}
4646

4747
HTTPUpdate::~HTTPUpdate(void)
@@ -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)