33
33
// To do extern "C" uint32_t _SPIFFS_end;
34
34
35
35
HTTPUpdate::HTTPUpdate (void )
36
- : _httpClientTimeout (8000 ), _ledPin(- 1 )
36
+ : HTTPUpdate (8000 )
37
37
{
38
- _followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS;
39
38
}
40
39
41
40
HTTPUpdate::HTTPUpdate (int httpClientTimeout)
42
41
: _httpClientTimeout(httpClientTimeout), _ledPin(-1 )
43
42
{
44
43
_followRedirects = HTTPC_DISABLE_FOLLOW_REDIRECTS;
44
+ _md5Sum = String ();
45
+ _user = String ();
46
+ _password = String ();
47
+ _auth = String ();
45
48
}
46
49
47
50
HTTPUpdate::~HTTPUpdate (void )
@@ -220,6 +223,14 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
220
223
requestCB (&http);
221
224
}
222
225
226
+ if (!_user.isEmpty () && !_password.isEmpty ()) {
227
+ http.setAuthorization (_user.c_str (), _password.c_str ());
228
+ }
229
+
230
+ if (!_auth.isEmpty ()) {
231
+ http.setAuthorization (_auth.c_str ());
232
+ }
233
+
223
234
const char * headerkeys[] = { " x-MD5" };
224
235
size_t headerkeyssize = sizeof (headerkeys) / sizeof (char *);
225
236
@@ -243,8 +254,14 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
243
254
log_d (" - code: %d\n " , code);
244
255
log_d (" - len: %d\n " , len);
245
256
246
- if (http.hasHeader (" x-MD5" )) {
247
- log_d (" - MD5: %s\n " , http.header (" x-MD5" ).c_str ());
257
+ String md5;
258
+ if (_md5Sum.length ()) {
259
+ md5 = _md5Sum;
260
+ } else if (http.hasHeader (" x-MD5" )) {
261
+ md5 = http.header (" x-MD5" );
262
+ }
263
+ if (md5.length ()) {
264
+ log_d (" - MD5: %s\n " ,md5.c_str ());
248
265
}
249
266
250
267
log_d (" ESP32 info:\n " );
@@ -341,7 +358,7 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
341
358
}
342
359
*/
343
360
}
344
- if (runUpdate (*tcp, len, http. header ( " x-MD5 " ) , command)) {
361
+ if (runUpdate (*tcp, len, md5 , command)) {
345
362
ret = HTTP_UPDATE_OK;
346
363
log_d (" Update ok\n " );
347
364
http.end ();
0 commit comments