This commit is contained in:
Proddy
2024-03-12 23:08:57 +01:00
parent 0bd57973c5
commit be6bb1de6a
4 changed files with 5 additions and 39 deletions

View File

@@ -27,7 +27,7 @@ ESP8266React::ESP8266React(AsyncWebServer * server, FS * fs)
static char last_modified[50];
sprintf(last_modified, "%s %s CET", __DATE__, __TIME__);
WWWData::registerRoutes([server](const String & uri, const String & contentType, const uint8_t * content, size_t len, const String & hash) {
WWWData::registerRoutes([server](const char * uri, const String & contentType, const uint8_t * content, size_t len, const String & hash) {
ArRequestHandlerFunction requestHandler = [contentType, content, len, hash](AsyncWebServerRequest * request) {
// Check if the client already has the same version and respond with a 304 (Not modified)
if (request->header("If-Modified-Since").indexOf(last_modified) > 0) {
@@ -36,7 +36,7 @@ ESP8266React::ESP8266React(AsyncWebServer * server, FS * fs)
return request->send(304);
}
AsyncWebServerResponse * response = request->beginResponse(contentType, content, len);
AsyncWebServerResponse * response = request->beginResponse_P(200, contentType, content, len);
response->addHeader("Content-Encoding", "gzip");
// response->addHeader("Content-Encoding", "br"); // only works over HTTPS
@@ -47,10 +47,10 @@ ESP8266React::ESP8266React(AsyncWebServer * server, FS * fs)
request->send(response);
};
server->on(uri.c_str(), HTTP_GET, requestHandler);
server->on(uri, HTTP_GET, requestHandler);
// Serving non matching get requests with "/index.html"
// OPTIONS get a straight up 200 response
if (uri.equals("/index.html")) {
if (strncmp(uri, "/index.html", 11) == 0) {
server->onNotFound([requestHandler](AsyncWebServerRequest * request) {
if (request->method() == HTTP_GET) {
requestHandler(request);
@@ -87,4 +87,4 @@ void ESP8266React::loop() {
_apSettingsService.loop();
_otaSettingsService.loop();
_mqttSettingsService.loop();
}
}