From 461b413af73b14b144394c594cf2f622b6165002 Mon Sep 17 00:00:00 2001 From: Joseph Francis Date: Fri, 22 Nov 2019 08:15:05 -0500 Subject: [PATCH 1/2] HTTPUpdateServer Allow external POSTS (CORS) --- .../src/ESP8266HTTPUpdateServer-impl.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h index 190a597066..7d79470795 100644 --- a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h +++ b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h @@ -23,7 +23,7 @@ static const char serverIndex[] PROGMEM = Firmware:
- +
FileSystem:
@@ -58,8 +58,24 @@ void ESP8266HTTPUpdateServerTemplate::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()) { From 0aff8390ec8f18c4ace838271f7a260a6a683fde Mon Sep 17 00:00:00 2001 From: Joseph Francis Date: Fri, 22 Nov 2019 08:19:19 -0500 Subject: [PATCH 2/2] Format Updates - POST HTTPUpdateServer --- .../src/ESP8266HTTPUpdateServer-impl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h index 7d79470795..7b21b0846f 100644 --- a/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h +++ b/libraries/ESP8266HTTPUpdateServer/src/ESP8266HTTPUpdateServer-impl.h @@ -23,7 +23,7 @@ static const char serverIndex[] PROGMEM = Firmware:
- +
FileSystem:
@@ -70,7 +70,7 @@ void ESP8266HTTPUpdateServerTemplate::setup(ESP8266WebServerTemplate Serial.printf("Unauthenticated Update\n"); return; } - }); + }); // handler for the /update form POST (once file upload finishes) _server->on(path.c_str(), HTTP_POST, [&](){