@@ -59,8 +59,24 @@ void ESP8266HTTPUpdateServerTemplate<ServerType>::setup(ESP8266WebServerTemplate
5959 _server->send_P (200 ,PSTR (" text/html" ), serverIndex);
6060 });
6161
62+ // handler for the /update form page - preflight options
63+ _server->on (path.c_str (), HTTP_OPTIONS, [&](){
64+ _server->sendHeader (" Access-Control-Allow-Headers" ," *" );
65+ _server->sendHeader (" Access-Control-Allow-Origin" ," *" );
66+ _server->send (200 ,F (" text/html" ),String (F (" y" )));
67+ },[&](){
68+ _authenticated = (_username == emptyString || _password == emptyString || _server->authenticate (_username.c_str (), _password.c_str ()));
69+ if (!_authenticated){
70+ if (_serial_output)
71+ Serial.printf (" Unauthenticated Update\n " );
72+ return ;
73+ }
74+ });
75+
6276// handler for the /update form POST (once file upload finishes)
6377 _server->on (path.c_str (), HTTP_POST, [&](){
78+ _server->sendHeader (" Access-Control-Allow-Headers" ," *" );
79+ _server->sendHeader (" Access-Control-Allow-Origin" ," *" );
6480if (!_authenticated)
6581return _server->requestAuthentication ();
6682if (Update.hasError ()) {