From 445dcaaabf18ba6093d38245856dc633a9138b06 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Fri, 5 May 2023 02:48:59 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=93=AF=20Adds=20captive=20portal=20handle?= =?UTF-8?q?r?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/CaptivePortalHandler.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 include/CaptivePortalHandler.h diff --git a/include/CaptivePortalHandler.h b/include/CaptivePortalHandler.h new file mode 100644 index 0000000..ae9367e --- /dev/null +++ b/include/CaptivePortalHandler.h @@ -0,0 +1,22 @@ +#include + +class CaptiveRequestHandler : public AsyncWebHandler { +public: + CaptiveRequestHandler() {} + virtual ~CaptiveRequestHandler() {} + + bool canHandle(AsyncWebServerRequest *request){ + //request->addInterestingHeader("ANY"); + return true; + } + + void handleRequest(AsyncWebServerRequest *request) { + AsyncResponseStream *response = request->beginResponseStream("text/html"); + response->print("Captive Portal"); + response->print("

This is out captive portal front page.

"); + response->printf("

You were trying to reach: http://%s%s

", request->host().c_str(), request->url().c_str()); + response->printf("

Try opening this link instead

", WiFi.softAPIP().toString().c_str()); + response->print(""); + request->send(response); + } +}; \ No newline at end of file