From aee138b71e027cd5ed05b7664bddd8810d0a6dbb Mon Sep 17 00:00:00 2001 From: Mr-Dave Date: Wed, 12 Mar 2025 12:58:07 -0600 Subject: [PATCH] Fix header responses for JS and CSS file types --- src/webu.hpp | 4 +++- src/webu_ans.cpp | 4 ++++ src/webu_html.cpp | 11 +++++++---- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/src/webu.hpp b/src/webu.hpp index 085bd96e..a6a3c0de 100644 --- a/src/webu.hpp +++ b/src/webu.hpp @@ -55,7 +55,9 @@ enum WEBUI_RESP { WEBUI_RESP_HTML = 0, WEBUI_RESP_JSON = 1, - WEBUI_RESP_TEXT = 2 + WEBUI_RESP_TEXT = 2, + WEBUI_RESP_JS = 3, + WEBUI_RESP_CSS = 4 }; struct ctx_webu_clients { diff --git a/src/webu_ans.cpp b/src/webu_ans.cpp index acf1a82d..5ebc45ae 100644 --- a/src/webu_ans.cpp +++ b/src/webu_ans.cpp @@ -710,6 +710,10 @@ void cls_webu_ans::mhd_send() MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE, "text/plain;"); } else if (resp_type == WEBUI_RESP_JSON) { MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE, "application/json;"); + } else if (resp_type == WEBUI_RESP_CSS) { + MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE, "text/css;"); + } else if (resp_type == WEBUI_RESP_JS) { + MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE, "text/javascript;"); } else { MHD_add_response_header (response, MHD_HTTP_HEADER_CONTENT_TYPE, "text/html"); } diff --git a/src/webu_html.cpp b/src/webu_html.cpp index eb393302..f323daab 100644 --- a/src/webu_html.cpp +++ b/src/webu_html.cpp @@ -1601,6 +1601,8 @@ void cls_webu_html::user_page() FILE *fp = NULL; webua->resp_page = ""; + webua->resp_type = WEBUI_RESP_HTML; + pos = app->cfg->conf_filename.find("/",0); if (pos == std::string::npos) { MOTION_LOG(ERR, TYPE_STREAM, NO_ERRNO @@ -1627,8 +1629,10 @@ void cls_webu_html::user_page() mylower(ext); if (ext == "json") { webua->resp_type = WEBUI_RESP_JSON; - } else if ((ext == "js") || (ext == "css")) { - webua->resp_type = WEBUI_RESP_TEXT; + } else if ((ext == "js") ) { + webua->resp_type = WEBUI_RESP_JS; + } else if ((ext == "css") ) { + webua->resp_type = WEBUI_RESP_CSS; } else if (ext == "html") { webua->resp_type = WEBUI_RESP_HTML; } else { @@ -1647,6 +1651,7 @@ void cls_webu_html::user_page() MOTION_LOG(ERR, TYPE_STREAM, NO_ERRNO , _("Invalid user requested file: %s") , fname.c_str()); + webua->resp_type = WEBUI_RESP_HTML; return; } else { while (fgets(response, PATH_MAX-1, fp)) { @@ -1654,8 +1659,6 @@ void cls_webu_html::user_page() } myfclose(fp); } - - } void cls_webu_html::main()