Skip to content

Commit 0e4b110

Browse files
committed
simplify example per @mcspr suggestion
1 parent 9e45256 commit 0e4b110

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

libraries/ESP8266WebServer/examples/HelloServer/HelloServer.ino

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,32 +90,24 @@ void setup(void) {
9090
// Hook examples
9191

9292
server.addHook([](const String & method, const String & url, WiFiClient * client, ESP8266WebServer::ContentTypeFunction contentType) {
93-
(void)method;
94-
(void)url;
95-
(void)client;
96-
(void)contentType;
93+
(void)method; // GET, PUT, ...
94+
(void)url; // example: /root/myfile.html
95+
(void)client; // the webserver tcp client connection
96+
(void)contentType; // contentType(".html") => "text/html"
9797
Serial.printf("A useless web hook has passed\n");
9898
Serial.printf("(this hook is in 0x%08x area (401x=IRAM 402x=FLASH))\n", esp_get_program_counter());
9999
return ESP8266WebServer::CLIENT_REQUEST_CAN_CONTINUE;
100100
});
101101

102-
server.addHook([](const String & method, const String & url, WiFiClient * client, ESP8266WebServer::ContentTypeFunction contentType) {
103-
(void)method;
104-
(void)client;
105-
(void)contentType;
106-
Serial.printf("(this hook is in 0x%08x area (401x=IRAM 402x=FLASH))\n", esp_get_program_counter());
102+
server.addHook([](const String&, const String & url, WiFiClient*, ESP8266WebServer::ContentTypeFunction) {
107103
if (url.startsWith("/fail")) {
108104
Serial.printf("An always failing web hook has been triggered\n");
109105
return ESP8266WebServer::CLIENT_MUST_STOP;
110106
}
111107
return ESP8266WebServer::CLIENT_REQUEST_CAN_CONTINUE;
112108
});
113109

114-
server.addHook([](const String & method, const String & url, WiFiClient * client, ESP8266WebServer::ContentTypeFunction contentType) {
115-
(void)method;
116-
(void)client;
117-
(void)contentType;
118-
Serial.printf("(this hook is in 0x%08x area (401x=IRAM 402x=FLASH))\n", esp_get_program_counter());
110+
server.addHook([](const String&, const String & url, WiFiClient * client, ESP8266WebServer::ContentTypeFunction) {
119111
if (url.startsWith("/dump")) {
120112
Serial.printf("The dumper web hook is on the run\n");
121113

@@ -125,7 +117,7 @@ void setup(void) {
125117
// webserver.
126118
#ifdef STREAMTO_API
127119
// we are lucky
128-
client->streamToWithTimeout(Serial, 500);
120+
client->toWithTimeout(Serial, 500);
129121
#else
130122
auto last = millis();
131123
while ((millis() - last) < 500) {

0 commit comments

Comments
 (0)