From 655f9a9f797883735e4110db8f41c536db47f0b6 Mon Sep 17 00:00:00 2001 From: Sergey Lyubka Date: Tue, 20 Jul 2021 11:33:38 +0100 Subject: [PATCH] Add Content-Type header to the SSI files --- mongoose.c | 3 ++- mongoose.h | 1 + src/ssi.c | 3 ++- src/version.h | 1 + test/unit_test.c | 8 ++++++++ 5 files changed, 14 insertions(+), 2 deletions(-) diff --git a/mongoose.c b/mongoose.c index 2cce5737..fd0e218b 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3278,8 +3278,9 @@ static char *mg_ssi(const char *path, const char *root, int depth) { void mg_http_serve_ssi(struct mg_connection *c, const char *root, const char *fullpath) { + const char *headers = "Content-Type: text/html; charset=utf-8\r\n"; char *data = mg_ssi(fullpath, root, 0); - mg_http_reply(c, 200, "", "%s", data == NULL ? "" : data); + mg_http_reply(c, 200, headers, "%s", data == NULL ? "" : data); free(data); } #endif diff --git a/mongoose.h b/mongoose.h index 7db835c5..2bf4b3f7 100644 --- a/mongoose.h +++ b/mongoose.h @@ -14,6 +14,7 @@ // // Alternatively, you can license this software under a commercial // license, as set out in . + #ifndef MONGOOSE_H #define MONGOOSE_H diff --git a/src/ssi.c b/src/ssi.c index 3b49e2e6..e5fb1ee1 100644 --- a/src/ssi.c +++ b/src/ssi.c @@ -78,8 +78,9 @@ static char *mg_ssi(const char *path, const char *root, int depth) { void mg_http_serve_ssi(struct mg_connection *c, const char *root, const char *fullpath) { + const char *headers = "Content-Type: text/html; charset=utf-8\r\n"; char *data = mg_ssi(fullpath, root, 0); - mg_http_reply(c, 200, "", "%s", data == NULL ? "" : data); + mg_http_reply(c, 200, headers, "%s", data == NULL ? "" : data); free(data); } #endif diff --git a/src/version.h b/src/version.h index d4d960ba..28fde466 100644 --- a/src/version.h +++ b/src/version.h @@ -1,3 +1,4 @@ + #ifndef MONGOOSE_H #define MONGOOSE_H diff --git a/test/unit_test.c b/test/unit_test.c index 69d05c32..fb408178 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -507,6 +507,14 @@ static void test_http_server(void) { "recurse\n\n" "recurse\n\n" "recurse\n\n") == 0); + { + struct mg_http_message hm; + mg_http_parse(buf, strlen(buf), &hm); + ASSERT(mg_http_get_header(&hm, "Content-Length") != NULL); + ASSERT(mg_http_get_header(&hm, "Content-Type") != NULL); + ASSERT(mg_strcmp(*mg_http_get_header(&hm, "Content-Type"), + mg_str("text/html; charset=utf-8")) == 0); + } ASSERT(fetch(&mgr, buf, url, "GET /badroot HTTP/1.0\r\n\n") == 400); #if MG_ARCH == MG_ARCH_WIN32