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 )
@@ -217,6 +220,14 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
217
220
http.addHeader (" x-ESP32-version" , currentVersion);
218
221
}
219
222
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
+
220
231
const char * headerkeys[] = { " x-MD5" };
221
232
size_t headerkeyssize = sizeof (headerkeys) / sizeof (char *);
222
233
@@ -240,8 +251,14 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
240
251
log_d (" - code: %d\n " , code);
241
252
log_d (" - len: %d\n " , len);
242
253
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 ());
245
262
}
246
263
247
264
log_d (" ESP32 info:\n " );
@@ -338,7 +355,7 @@ HTTPUpdateResult HTTPUpdate::handleUpdate(HTTPClient& http, const String& curren
338
355
}
339
356
*/
340
357
}
341
- if (runUpdate (*tcp, len, http. header ( " x-MD5 " ) , command)) {
358
+ if (runUpdate (*tcp, len, md5 , command)) {
342
359
ret = HTTP_UPDATE_OK;
343
360
log_d (" Update ok\n " );
344
361
http.end ();
0 commit comments