Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTPUpdateServer Allow external POSTS (CORS) #6824

Merged
merged 8 commits into from
Jun 27, 2022
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,24 @@ void ESP8266HTTPUpdateServerTemplate<ServerType>::setup(ESP8266WebServerTemplate
_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)
_server->on(path.c_str(), HTTP_POST, [&](){
_server->sendHeader("Access-Control-Allow-Headers", "*");
_server->sendHeader("Access-Control-Allow-Origin", "*");
if(!_authenticated)
return _server->requestAuthentication();
if (Update.hasError()) {
Expand Down