From 8f018732d38a70868271608e279727b6f68176f5 Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Wed, 4 Jan 2023 17:15:40 +0100 Subject: [PATCH 1/2] Update feature.yaml --- .github/ISSUE_TEMPLATE/feature.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/feature.yaml b/.github/ISSUE_TEMPLATE/feature.yaml index a7a4bcfd..a5c3cf20 100644 --- a/.github/ISSUE_TEMPLATE/feature.yaml +++ b/.github/ISSUE_TEMPLATE/feature.yaml @@ -1,6 +1,6 @@ name: 💡 Feature Request description: Use this form if you have an idea or wish for a new feature -labels: feature +labels: enhancement body: From da9f9428576fb10c1166ba46e0e7cde4d47e1d52 Mon Sep 17 00:00:00 2001 From: CaCO3 Date: Wed, 4 Jan 2023 20:31:04 +0100 Subject: [PATCH 2/2] cache static files (#1755) Co-authored-by: CaCO3 --- .../jomjol_fileserver_ota/server_help.cpp | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/code/components/jomjol_fileserver_ota/server_help.cpp b/code/components/jomjol_fileserver_ota/server_help.cpp index c602ebce..4bf18a7f 100644 --- a/code/components/jomjol_fileserver_ota/server_help.cpp +++ b/code/components/jomjol_fileserver_ota/server_help.cpp @@ -28,6 +28,15 @@ static const char *TAG = "SERVER HELP"; char scratch[SERVER_HELPER_SCRATCH_BUFSIZE]; + +bool endsWith(std::string const &str, std::string const &suffix) { + if (str.length() < suffix.length()) { + return false; + } + return str.compare(str.length() - suffix.length(), suffix.length(), suffix) == 0; +} + + esp_err_t send_file(httpd_req_t *req, std::string filename) { FILE *fd = fopen(filename.c_str(), "r"); @@ -40,6 +49,21 @@ esp_err_t send_file(httpd_req_t *req, std::string filename) ESP_LOGD(TAG, "Sending file: %s ...", filename.c_str()); // httpd_resp_set_hdr(req, "Access-Control-Allow-Origin", "*"); + + /* For all files with the following file extention tell + the webbrowser to cache them for 24h */ + if (endsWith(filename, ".html") || + endsWith(filename, ".htm") || + endsWith(filename, ".css") || + endsWith(filename, ".js") || + endsWith(filename, ".map") || + endsWith(filename, ".jpg") || + endsWith(filename, ".jpeg") || + endsWith(filename, ".ico") || + endsWith(filename, ".png")) { + httpd_resp_set_hdr(req, "Cache-Control", "max-age=86400"); + } + set_content_type_from_file(req, filename.c_str()); /* Retrieve the pointer to scratch buffer for temporary storage */