httpNotFound remove trailing slash

This commit is contained in:
Patrick Haßel 2025-02-19 15:59:16 +01:00
parent 8c8c35fb5f
commit 97f711a22d

View File

@ -5,15 +5,18 @@
AsyncWebServer server(80); AsyncWebServer server(80);
void httpNotFound(AsyncWebServerRequest *request) { void httpNotFound(AsyncWebServerRequest* request) {
if (request->method() == HTTP_OPTIONS) { const String path = request->url();
if (path.endsWith("/") && path.length() > 1) {
request->redirect(path.substring(0, path.length() - 1));
} else if (request->method() == HTTP_OPTIONS) {
request->send(200); request->send(200);
} else { } else {
request->send(404, "text/plain", "not found"); request->send(404, "text/plain", "not found");
} }
} }
void httpRestart([[maybe_unused]] AsyncWebServerRequest *request) { void httpRestart([[maybe_unused]] AsyncWebServerRequest* request) {
systemRequestRestart(); systemRequestRestart();
request->send(200, "application/json", "true"); request->send(200, "application/json", "true");
} }
@ -30,4 +33,4 @@ void httpSetup() {
void httpStop() { void httpStop() {
server.end(); server.end();
} }