diff --git a/WiFiManager.cpp b/WiFiManager.cpp index 8ec7131b..a8ea2537 100644 --- a/WiFiManager.cpp +++ b/WiFiManager.cpp @@ -2386,16 +2386,20 @@ void WiFiManager::handleNotFound() { if (captivePortal()) return; // If captive portal redirect instead of displaying the page handleRequest(); String message = FPSTR(S_notfound); // @token notfound - message += FPSTR(S_uri); // @token uri - message += server->uri(); - message += FPSTR(S_method); // @token method - message += ( server->method() == HTTP_GET ) ? FPSTR(S_GET) : FPSTR(S_POST); - message += FPSTR(S_args); // @token args - message += server->args(); - message += F("\n"); - - for ( uint8_t i = 0; i < server->args(); i++ ) { - message += " " + server->argName ( i ) + ": " + server->arg ( i ) + "\n"; + + bool verbose404 = false; // show info in 404 body, uri,method, args + if(verbose404){ + message += FPSTR(S_uri); // @token uri + message += server->uri(); + message += FPSTR(S_method); // @token method + message += ( server->method() == HTTP_GET ) ? FPSTR(S_GET) : FPSTR(S_POST); + message += FPSTR(S_args); // @token args + message += server->args(); + message += F("\n"); + + for ( uint8_t i = 0; i < server->args(); i++ ) { + message += " " + server->argName ( i ) + ": " + server->arg ( i ) + "\n"; + } } server->sendHeader(F("Cache-Control"), F("no-cache, no-store, must-revalidate")); // @HTTPHEAD send cache server->sendHeader(F("Pragma"), F("no-cache")); diff --git a/WiFiManager.h b/WiFiManager.h index ce0de122..095859fd 100644 --- a/WiFiManager.h +++ b/WiFiManager.h @@ -660,13 +660,16 @@ class WiFiManager void updateConxResult(uint8_t status); // webserver handlers +public: + void handleNotFound(); +private: void HTTPSend(const String &content); void handleRoot(); void handleWifi(boolean scan); void handleWifiSave(); void handleInfo(); void handleReset(); - void handleNotFound(); + void handleExit(); void handleClose(); // void handleErase(); diff --git a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino index 7509ba10..aab2c6a0 100644 --- a/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino +++ b/examples/Super/OnDemandConfigPortal/OnDemandConfigPortal.ino @@ -72,8 +72,12 @@ void saveParamCallback(){ } void bindServerCallback(){ - wm.server->on("/custom",handleRoute); // this is now crashing esp32 for some reason - // wm.server->on("/info",handleRoute); // you can override wm! + wm.server->on("/custom",handleRoute); + + // you can override wm route endpoints, I have not found a way to remove handlers, but this would let you disable them or add auth etc. + // wm.server->on("/info",handleNotFound); + // wm.server->on("/update",handleNotFound); + wm.server->on("/erase",handleNotFound); } void handleRoute(){ @@ -81,6 +85,11 @@ void handleRoute(){ wm.server->send(200, "text/plain", "hello from user code"); } +void handleNotFound(){ + Serial.println("[HTTP] handle route"); + wm.handleNotFound(); +} + void handlePreOtaUpdateCallback(){ Update.onProgress([](unsigned int progress, unsigned int total) { Serial.printf("CUSTOM Progress: %u%%\r", (progress / (total / 100)));