From 94271c59a695f96f45c92eb30810d73eef5d7c03 Mon Sep 17 00:00:00 2001 From: nouser2013 <6624032+nouser2013@users.noreply.github.com> Date: Sat, 22 Jun 2019 18:09:47 +0200 Subject: [PATCH] Added example to determine interface inside callbacks (#446) --- README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/README.md b/README.md index f013dda..7e28aa2 100644 --- a/README.md +++ b/README.md @@ -70,6 +70,7 @@ To use this library you might need to have the latest git versions of [ESP32](ht - [Serve different site files in AP mode](#serve-different-site-files-in-ap-mode) - [Rewrite to different index on AP](#rewrite-to-different-index-on-ap) - [Serving different hosts](#serving-different-hosts) + - [Determine interface inside callbacks](#determine-interface-inside-callbacks) - [Bad Responses](#bad-responses) - [Respond with content using a callback without content length to HTTP/1.0 clients](#respond-with-content-using-a-callback-without-content-length-to-http10-clients) - [Async WebSocket Plugin](#async-websocket-plugin) @@ -885,6 +886,18 @@ server.serveStatic("/", SPIFFS, "/host1/").setFilter(filterOnHost1); server.serveStatic("/", SPIFFS, "/www/"); ``` +### Determine interface inside callbacks +```cpp + String RedirectUrl = "http://"; + if (ON_STA_FILTER(request)) { + RedirectUrl += WiFi.localIP().toString(); + } else { + RedirectUrl += WiFi.softAPIP().toString(); + } + RedirectUrl += "/index.htm"; + request->redirect(RedirectUrl); +``` + ## Bad Responses Some responses are implemented, but you should not use them, because they do not conform to HTTP. The following example will lead to unclean close of the connection and more time wasted