Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.

Commit 94271c5

Browse files
nouser2013me-no-dev
authored andcommitted
Added example to determine interface inside callbacks (me-no-dev#446)
1 parent 0460202 commit 94271c5

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

README.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ To use this library you might need to have the latest git versions of [ESP32](ht
7070
- [Serve different site files in AP mode](#serve-different-site-files-in-ap-mode)
7171
- [Rewrite to different index on AP](#rewrite-to-different-index-on-ap)
7272
- [Serving different hosts](#serving-different-hosts)
73+
- [Determine interface inside callbacks](#determine-interface-inside-callbacks)
7374
- [Bad Responses](#bad-responses)
7475
- [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)
7576
- [Async WebSocket Plugin](#async-websocket-plugin)
@@ -885,6 +886,18 @@ server.serveStatic("/", SPIFFS, "/host1/").setFilter(filterOnHost1);
885886
server.serveStatic("/", SPIFFS, "/www/");
886887
```
887888
889+
### Determine interface inside callbacks
890+
```cpp
891+
String RedirectUrl = "http://";
892+
if (ON_STA_FILTER(request)) {
893+
RedirectUrl += WiFi.localIP().toString();
894+
} else {
895+
RedirectUrl += WiFi.softAPIP().toString();
896+
}
897+
RedirectUrl += "/index.htm";
898+
request->redirect(RedirectUrl);
899+
```
900+
888901
## Bad Responses
889902
Some responses are implemented, but you should not use them, because they do not conform to HTTP.
890903
The following example will lead to unclean close of the connection and more time wasted

0 commit comments

Comments
 (0)