3333// To do extern "C" uint32_t _SPIFFS_end;
3434
3535HTTPUpdate::HTTPUpdate (void )
36- : _httpClientTimeout (8000 ), _ledPin(- 1 )
36+ : HTTPUpdate (8000 )
3737{
38- _followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS;
3938}
4039
4140HTTPUpdate::HTTPUpdate (int httpClientTimeout)
4241 : _httpClientTimeout(httpClientTimeout), _ledPin(-1 )
4342{
4443 _followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS;
44+ _md5Sum = String ();
45+ _user = String ();
46+ _password = String ();
47+ _auth = String ();
4548}
4649
4750HTTPUpdate::~HTTPUpdate (void )
@@ -217,6 +220,14 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
217220 http.addHeader (" x-ESP32-version" , currentVersion);
218221 }
219222
223+ if (!_user.isEmpty () && !_password.isEmpty ()) {
224+ http.setAuthorization (_user.c_str (), _password.c_str ());
225+ }
226+
227+ if (!_auth.isEmpty ()) {
228+ http.setAuthorization (_auth.c_str ());
229+ }
230+
220231 const char * headerkeys[] = { " x-MD5" };
221232 size_t headerkeyssize = sizeof (headerkeys) / sizeof (char *);
222233
@@ -240,8 +251,14 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
240251 log_d (" - code: %d\n " , code);
241252 log_d (" - len: %d\n " , len);
242253
243- if (http.hasHeader (" x-MD5" )) {
244- log_d (" - MD5: %s\n " , http.header (" x-MD5" ).c_str ());
254+ String md5;
255+ if (_md5Sum.length ()) {
256+ md5 = _md5Sum;
257+ } else if (http.hasHeader (" x-MD5" )) {
258+ md5 = http.header (" x-MD5" );
259+ }
260+ if (md5.length ()) {
261+ log_d (" - MD5: %s\n " ,md5.c_str ());
245262 }
246263
247264 log_d (" ESP32 info:\n " );
@@ -338,7 +355,7 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
338355 }
339356*/
340357 }
341- if (runUpdate (*tcp, len, http. header ( " x-MD5 " ) , command)) {
358+ if (runUpdate (*tcp, len, md5 , command)) {
342359 ret = HTTP_UPDATE_OK;
343360 log_d (" Update ok\n " );
344361 http.end ();
0 commit comments