commit bbd47e1427940e0d4f22a098acd593c1365accd3
parent d2013a6337972c62a71f01324e87af0e55579245
Author: Laslo Hunhold <dev@frign.de>
Date:   Wed,  2 Jan 2019 17:04:23 +0100
Specify UTF-8 for non-binary content-types
If charset is unspecified, the encoding falls back to ISO 8859-1 or
something else that is defined in HTTP/1.1.
Given there is no reason not to use UTF-8 nowadays[0] and one can convert
legacy encodings to UTF-8 easily, if the case comes up, it is a sane
default to specify it in the config.def.h.
[0]: https://utf8everywhere.org/
Signed-off-by: Laslo Hunhold <dev@frign.de>
Diffstat:
3 files changed, 12 insertions(+), 12 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -6,15 +6,15 @@ static const struct {
 	char *ext;
 	char *type;
 } mimes[] = {
-	{ "xml",   "application/xml" },
-	{ "xhtml", "application/xhtml+xml" },
-	{ "html",  "text/html; charset=UTF-8" },
-	{ "htm",   "text/html; charset=UTF-8" },
-	{ "css",   "text/css" },
-	{ "txt",   "text/plain" },
-	{ "md",    "text/plain" },
-	{ "c",     "text/plain" },
-	{ "h",     "text/plain" },
+	{ "xml",   "application/xml; charset=utf-8" },
+	{ "xhtml", "application/xhtml+xml; charset=utf-8" },
+	{ "html",  "text/html; charset=utf-8" },
+	{ "htm",   "text/html; charset=utf-8" },
+	{ "css",   "text/css; charset=utf-8" },
+	{ "txt",   "text/plain; charset=utf-8" },
+	{ "md",    "text/plain; charset=utf-8" },
+	{ "c",     "text/plain; charset=utf-8" },
+	{ "h",     "text/plain; charset=utf-8" },
 	{ "gz",    "application/x-gtar" },
 	{ "tar",   "application/tar" },
 	{ "pdf",   "application/x-pdf" },
@@ -24,7 +24,7 @@ static const struct {
 	{ "jpg",   "image/jpg" },
 	{ "iso",   "application/x-iso9660-image" },
 	{ "webp",  "image/webp" },
-	{ "svg",   "image/svg+xml" },
+	{ "svg",   "image/svg+xml; charset=utf-8" },
 	{ "flac",  "audio/flac" },
 	{ "mp3",   "audio/mpeg" },
 	{ "ogg",   "audio/ogg" },
diff --git a/http.c b/http.c
@@ -58,7 +58,7 @@ http_send_status(int fd, enum status s)
 	            "Date: %s\r\n"
 	            "Connection: close\r\n"
 	            "%s"
-	            "Content-Type: text/html\r\n"
+	            "Content-Type: text/html; charset=utf-8\r\n"
 	            "\r\n"
 	            "<!DOCTYPE html>\n<html>\n\t<head>\n"
 	            "\t\t<title>%d %s</title>\n\t</head>\n\t<body>\n"
diff --git a/resp.c b/resp.c
@@ -56,7 +56,7 @@ resp_dir(int fd, char *name, struct request *r)
 	            "HTTP/1.1 %d %s\r\n"
 	            "Date: %s\r\n"
 	            "Connection: close\r\n"
-		    "Content-Type: text/html\r\n"
+		    "Content-Type: text/html; charset=utf-8\r\n"
 		    "\r\n",
 	            S_OK, status_str[S_OK], timestamp(time(NULL), t)) < 0) {
 		s = S_REQUEST_TIMEOUT;