From 97f711a22d80d62580087429c88181b6fe0e3205 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Ha=C3=9Fel?= Date: Wed, 19 Feb 2025 15:59:16 +0100 Subject: [PATCH] httpNotFound remove trailing slash --- src/patrix/http.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/patrix/http.cpp b/src/patrix/http.cpp index c1af68a..7e0340b 100644 --- a/src/patrix/http.cpp +++ b/src/patrix/http.cpp @@ -5,15 +5,18 @@ AsyncWebServer server(80); -void httpNotFound(AsyncWebServerRequest *request) { - if (request->method() == HTTP_OPTIONS) { +void httpNotFound(AsyncWebServerRequest* request) { + 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); } else { request->send(404, "text/plain", "not found"); } } -void httpRestart([[maybe_unused]] AsyncWebServerRequest *request) { +void httpRestart([[maybe_unused]] AsyncWebServerRequest* request) { systemRequestRestart(); request->send(200, "application/json", "true"); } @@ -30,4 +33,4 @@ void httpSetup() { void httpStop() { server.end(); -} \ No newline at end of file +}