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:
parent
9668f77070
commit
678a477559
@ -59,8 +59,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()) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user