Added example to determine interface inside callbacks (#446)

This commit is contained in:
nouser2013 authored and Me No Dev committed 2019-06-22 18:09:47 +02:00
1 parent 046020228d
commit 94271c59a6
1 file changed
+13
+13
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) - [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) - [Rewrite to different index on AP](#rewrite-to-different-index-on-ap)
- [Serving different hosts](#serving-different-hosts) - [Serving different hosts](#serving-different-hosts)
- [Determine interface inside callbacks](#determine-interface-inside-callbacks)
- [Bad Responses](#bad-responses) - [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) - [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) - [Async WebSocket Plugin](#async-websocket-plugin)
@@ -885,6 +886,18 @@ server.serveStatic("/", SPIFFS, "/host1/").setFilter(filterOnHost1);
server.serveStatic("/", SPIFFS, "/www/"); 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 ## Bad Responses
Some responses are implemented, but you should not use them, because they do not conform to HTTP. 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 The following example will lead to unclean close of the connection and more time wasted