Added example to determine interface inside callbacks (#446)

This commit is contained in:
nouser2013 2019-06-22 18:09:47 +02:00 committed by Me No Dev
parent 046020228d
commit 94271c59a6
1 changed files with 13 additions and 0 deletions

View File

@ -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