Skip to content

Commit 1234d9d

Browse files
hookedupjoejoefran
authored andcommitted
HTTPUpdateServer Allow external POSTS (CORS) (esp8266#6824)
* HTTPUpdateServer Allow external POSTS (CORS) * Format Updates - POST HTTPUpdateServer Co-authored-by: Joseph Francis <[email protected]>
1 parent 82d8ff6 commit 1234d9d

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

Diff for: libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h

+16
Original file line numberDiff line numberDiff line change
@@ -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", "*");
6480
if(!_authenticated)
6581
return _server->requestAuthentication();
6682
if (Update.hasError()) {

0 commit comments

Comments
 (0)