1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-04-19 23:22:16 +03:00

HTTPUpdateServer Allow external POSTS (CORS) (#6824)

* HTTPUpdateServer Allow external POSTS (CORS)

* Format Updates - POST HTTPUpdateServer

Co-authored-by: Joseph Francis <joefran@us.ibm.com>
This commit is contained in:
Joseph Francis 2022-06-27 17:06:10 -04:00 committed by GitHub
parent 9668f77070
commit 678a477559
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -59,8 +59,24 @@ void ESP8266HTTPUpdateServerTemplate<ServerType>::setup(ESP8266WebServerTemplate
_server->send_P(200, PSTR("text/html"), serverIndex); _server->send_P(200, PSTR("text/html"), serverIndex);
}); });
// handler for the /update form page - preflight options
_server->on(path.c_str(), HTTP_OPTIONS, [&](){
_server->sendHeader("Access-Control-Allow-Headers", "*");
_server->sendHeader("Access-Control-Allow-Origin", "*");
_server->send(200, F("text/html"), String(F("y")));
},[&](){
_authenticated = (_username == emptyString || _password == emptyString || _server->authenticate(_username.c_str(), _password.c_str()));
if(!_authenticated){
if (_serial_output)
Serial.printf("Unauthenticated Update\n");
return;
}
});
// handler for the /update form POST (once file upload finishes) // handler for the /update form POST (once file upload finishes)
_server->on(path.c_str(), HTTP_POST, [&](){ _server->on(path.c_str(), HTTP_POST, [&](){
_server->sendHeader("Access-Control-Allow-Headers", "*");
_server->sendHeader("Access-Control-Allow-Origin", "*");
if(!_authenticated) if(!_authenticated)
return _server->requestAuthentication(); return _server->requestAuthentication();
if (Update.hasError()) { if (Update.hasError()) {