mirror of
https://github.com/alexhopeoconnor/WiFiManager.git
synced 2026-10-04 02:48:13 +10:00
move 404 handler public, remove 404 info, add examples for overrides
This commit is contained in:
+13
-9
@@ -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"));
|
||||
|
||||
+4
-1
@@ -646,13 +646,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();
|
||||
|
||||
@@ -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)));
|
||||
|
||||
Reference in New Issue
Block a user