@@ -43,6 +43,26 @@ ESP8266HTTPUpdate::~ESP8266HTTPUpdate(void)
43
43
{
44
44
}
45
45
46
+ /* *
47
+ * set the Authorization for the http request
48
+ * @param user const String&
49
+ * @param password const String&
50
+ */
51
+ void ESP8266HTTPUpdate::setAuthorization (const String &user, const String &password)
52
+ {
53
+ _user = user;
54
+ _password = password;
55
+ }
56
+
57
+ /* *
58
+ * set the Authorization for the http request
59
+ * @param auth const String& base64
60
+ */
61
+ void ESP8266HTTPUpdate::setAuthorization (const String &auth)
62
+ {
63
+ _auth = auth;
64
+ }
65
+
46
66
#if HTTPUPDATE_1_2_COMPATIBLE
47
67
HTTPUpdateResult ESP8266HTTPUpdate::update (const String& url, const String& currentVersion,
48
68
const String& httpsFingerprint, bool reboot)
@@ -241,6 +261,8 @@ String ESP8266HTTPUpdate::getLastErrorString(void)
241
261
return F (" Verify Bin Header Failed" );
242
262
case HTTP_UE_BIN_FOR_WRONG_FLASH:
243
263
return F (" New Binary Does Not Fit Flash Size" );
264
+ case HTTP_UE_SERVER_UNAUTHORIZED:
265
+ return F (" Unauthorized (401)" );
244
266
}
245
267
246
268
return String ();
@@ -282,6 +304,16 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
282
304
http.addHeader (F (" x-ESP8266-version" ), currentVersion);
283
305
}
284
306
307
+ if (!_user.isEmpty () && !_password.isEmpty ())
308
+ {
309
+ http.setAuthorization (_user.c_str (), _password.c_str ());
310
+ }
311
+
312
+ if (!_auth.isEmpty ())
313
+ {
314
+ http.setAuthorization (_auth.c_str ());
315
+ }
316
+
285
317
const char * headerkeys[] = { " x-MD5" };
286
318
size_t headerkeyssize = sizeof (headerkeys) / sizeof (char *);
287
319
@@ -432,6 +464,10 @@ HTTPUpdateResult ESP8266HTTPUpdate::handleUpdate(HTTPClient& http, const String&
432
464
_setLastError (HTTP_UE_SERVER_FORBIDDEN);
433
465
ret = HTTP_UPDATE_FAILED;
434
466
break ;
467
+ case HTTP_CODE_UNAUTHORIZED:
468
+ _setLastError (HTTP_UE_SERVER_UNAUTHORIZED);
469
+ ret = HTTP_UPDATE_FAILED;
470
+ break ;
435
471
default :
436
472
_setLastError (HTTP_UE_SERVER_WRONG_HTTP_CODE);
437
473
ret = HTTP_UPDATE_FAILED;
0 commit comments