Browse Source

further improvments, [this] in lambda fcn callback, compressed gz webfiles via streamFile()

tags/FSM1.0
Simon Schmidt 3 years ago
parent
commit
10b57ca516
5 changed files with 41 additions and 19 deletions
  1. BIN
      data/comp.html.gz
  2. 12
    0
      data/compress.html
  3. BIN
      data/compress.html.gz
  4. 28
    0
      lib/httpserver/httpserver.h
  5. 1
    19
      src/main.cpp

BIN
data/comp.html.gz View File


+ 12
- 0
data/compress.html View File

<!DOCTYPE html>
<html>

<head>
<title>Ich bin ein komrpimierter Test</title>
I bims der Head
</head>
<body>
I bims der Body
</body>

</html>

BIN
data/compress.html.gz View File


+ 28
- 0
lib/httpserver/httpserver.h View File

streamFile(f, cont); 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() ){ if( this->addRootFileHandler() ){
this->begin(); this->begin();

+ 1
- 19
src/main.cpp View File

stairs.task(); stairs.task();
} }


// HTTP
void handleNotFound();
// port 80, root directory of server '/'
HTTPServer httpServer(80, "/"); HTTPServer httpServer(80, "/");


uint32_t _t=0; 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() { void setup() {
#ifdef WITH_DEBUGGING_ON #ifdef WITH_DEBUGGING_ON
ota_setup(); ota_setup();


httpServer.start(); httpServer.start();
httpServer.onNotFound(handleNotFound);
Serial.println("HTTP server started !"); Serial.println("HTTP server started !");


stairs.setup(); stairs.setup();

Loading…
Cancel
Save