Fix header responses for JS and CSS file types

This commit is contained in:
Mr-Dave
2025-03-12 12:58:07 -06:00
parent 6e685d8bc1
commit aee138b71e
3 changed files with 14 additions and 5 deletions

View File

@@ -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 {

View File

@@ -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");
}

View File

@@ -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()