From 0a2d3c0e316b069fed50e77d8c20fc58e1539e93 Mon Sep 17 00:00:00 2001 From: Niklas Jensen Date: Mon, 26 Jan 2026 13:24:19 +0100 Subject: [PATCH] UNTESTED: fix for sending proper content type on config endpoint --- esp32/include/utils/string_utils.hpp | 12 ++++++++++++ esp32/src/filesystem.cpp | 9 ++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) create mode 100644 esp32/include/utils/string_utils.hpp diff --git a/esp32/include/utils/string_utils.hpp b/esp32/include/utils/string_utils.hpp new file mode 100644 index 0000000..ecd0f91 --- /dev/null +++ b/esp32/include/utils/string_utils.hpp @@ -0,0 +1,12 @@ +#pragma once +#include + +// Source - https://stackoverflow.com/a +// Posted by Joseph, modified by community. See post 'Timeline' for change history +// Retrieved 2026-01-26, License - CC BY-SA 3.0 + +inline bool ends_with(std::string const & value, std::string const & ending) +{ + if (ending.size() > value.size()) return false; + return std::equal(ending.rbegin(), ending.rend(), value.rbegin()); +} diff --git a/esp32/src/filesystem.cpp b/esp32/src/filesystem.cpp index 278ecda..45074f4 100644 --- a/esp32/src/filesystem.cpp +++ b/esp32/src/filesystem.cpp @@ -2,6 +2,7 @@ #include #include #include +#include "utils/string_utils.hpp" static const char *TAG = "FileService"; @@ -107,7 +108,13 @@ esp_err_t getConfigFile(httpd_req_t *request) { } String content = file.readString(); file.close(); - httpd_resp_set_type(request, "application/json"); + if (ends_with(path, ".pb")) { + httpd_resp_set_type(request, "application/x-protobuf"); + } else if (ends_with(path, ".json")) { + httpd_resp_set_type(request, "application/json"); + } else { + httpd_resp_set_type(request, "text/plain"); + } return httpd_resp_send(request, content.c_str(), content.length()); }