Add Content-Type header to the SSI files

This commit is contained in:
Sergey Lyubka 2021-07-20 11:33:38 +01:00
parent 3982e065c8
commit 655f9a9f79
5 changed files with 14 additions and 2 deletions

View File

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

View File

@ -14,6 +14,7 @@
//
// Alternatively, you can license this software under a commercial
// license, as set out in <https://www.cesanta.com/license>.
#ifndef MONGOOSE_H
#define MONGOOSE_H

View File

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

View File

@ -1,3 +1,4 @@
#ifndef MONGOOSE_H
#define MONGOOSE_H

View File

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