From 10b57ca51625c27ba72f87e48e845dfcc12e7b49 Mon Sep 17 00:00:00 2001 From: Simon Schmidt Date: Sat, 26 Jun 2021 09:21:34 +0200 Subject: [PATCH] further improvments, [this] in lambda fcn callback, compressed gz webfiles via streamFile() --- data/comp.html.gz | Bin 0 -> 135 bytes data/compress.html | 12 ++++++++++++ data/compress.html.gz | Bin 591 -> 139 bytes lib/httpserver/httpserver.h | 28 ++++++++++++++++++++++++++++ src/main.cpp | 20 +------------------- 5 files changed, 41 insertions(+), 19 deletions(-) create mode 100644 data/comp.html.gz create mode 100644 data/compress.html diff --git a/data/comp.html.gz b/data/comp.html.gz new file mode 100644 index 0000000000000000000000000000000000000000..ed3aee40c5ae43ff80d34fcf61a0b012524ddec4 GIT binary patch literal 135 zcmV;20C@i&iwFp1)7D@D|6^}$a4u+cZEOIuQFQTl4v7qKRmdpG&9UR7lt8oH~fz&|dz{)|c002yA + + + + Ich bin ein komrpimierter Test + I bims der Head + + + I bims der Body + + + \ No newline at end of file diff --git a/data/compress.html.gz b/data/compress.html.gz index 0ae04ee81c8f09333feddaadc7ee494d45479df7..4f0b0012302b7a740ce20a5a380f4cdd38bba1c8 100644 GIT binary patch literal 139 zcmV;60CfK!iwFo1($-)A17mM(aB^jHb1rCfZEOIuQFQTl4v7qKRmdpG&9UR7lt8oH~fz&|dz{)|c002yAhE zoFt}>6WLDJ?$_hk?wYUBLJ?OvwvXTU_&jZ#;Og${$H(sv_b68dTfKb~xMvdqNpyrz zpr~T7y8rg@Zhmuv9tBhta7N=?1-@M~X;+?y3PL%OYR>@496%w@vx|)K4axqbX<@Oe6uF$GsqCnrn}h`4|R;sB$m>tn6a@vXern!ze#A0 z=DQQ=Fe;P1)l29W#f(U8vni|e87Kp6Phhuugwc$@M=@{(;?|a-H%6;&BO&-oR2?Kf0n^eOpvp<=1_q2ozz|JBY@&7bR2=dfbu+ngO*K<36Uk@-;+U>i zDX(hfnjr|!^x0gpfQ;#6W0k*Df)OXhA@_5$8KZ*o5Kr}!>>3t2+7edlr0Xd@S|L<& z;}&94lr>kgiA_6-+lfwnk!X*~S~ca`5}b;y@MVyeqEqkcdK&n4U#m?PLMJ*K28w{9 zyP9u+a0q)YLx4kwuYp{&K`tD~LHkB9UVyTBk$NAv_oD-`dFl5s zDq3`Zmt*u!u{)ET@wy0C57yGbYJ|rK_4$m^S+?mc9Ua@1Q6ytP^p$0AK^@9i&`KdG dVtuWeY9~MSr5X5k!R4E8gI~1gPu(*J001vu9#;SW diff --git a/lib/httpserver/httpserver.h b/lib/httpserver/httpserver.h index 3a7e848..3574b55 100644 --- a/lib/httpserver/httpserver.h +++ b/lib/httpserver/httpserver.h @@ -46,6 +46,34 @@ public: streamFile(f, cont); } }); + on("/comp.html", [this]() { + File f = open("/comp.html.gz"); + if (!f) { + Serial.println("Failed to open file for reading"); + + } + else + { + Serial.println("Streaming /comp.html.gz to client"); + const String cont = "text/html"; + streamFile(f, cont); + } + }); + onNotFound([this]() { + String message = "File Not Found\n\n"; + message += "URI: "; + message += uri(); + message += "\nMethod: "; + message += (method() == HTTP_GET) ? "GET" : "POST"; + message += "\nArguments: "; + message += args(); + message += "\n"; + + for (uint8_t i = 0; i < args(); i++) { + message += " " + argName(i) + ": " + arg(i) + "\n"; + } + send(404, "text/plain", message); + }); if( this->addRootFileHandler() ){ this->begin(); diff --git a/src/main.cpp b/src/main.cpp index 9079023..bffeab4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,8 +34,7 @@ void timerCallback(void *pArg) stairs.task(); } -// HTTP -void handleNotFound(); +// port 80, root directory of server '/' HTTPServer httpServer(80, "/"); uint32_t _t=0; @@ -44,22 +43,6 @@ uint32_t _t=0; // =============================================== -void handleNotFound() { - String message = "File Not Found\n\n"; - message += "URI: "; - message += httpServer.uri(); - message += "\nMethod: "; - message += (httpServer.method() == HTTP_GET) ? "GET" : "POST"; - message += "\nArguments: "; - message += httpServer.args(); - message += "\n"; - - for (uint8_t i = 0; i < httpServer.args(); i++) { - message += " " + httpServer.argName(i) + ": " + httpServer.arg(i) + "\n"; - } - - httpServer.send(404, "text/plain", message); -} void setup() { #ifdef WITH_DEBUGGING_ON @@ -95,7 +78,6 @@ void setup() { ota_setup(); httpServer.start(); - httpServer.onNotFound(handleNotFound); Serial.println("HTTP server started !"); stairs.setup();