[hackers] [quark] Specify UTF-8 for non-binary content-types || Laslo Hunhold

From: <git_AT_suckless.org>
Date: Wed, 2 Jan 2019 17:05:36 +0100 (CET)

commit bbd47e1427940e0d4f22a098acd593c1365accd3
Author: Laslo Hunhold <dev_AT_frign.de>
AuthorDate: Wed Jan 2 17:04:23 2019 +0100
Commit: Laslo Hunhold <dev_AT_frign.de>
CommitDate: Wed Jan 2 17:04:23 2019 +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_AT_frign.de>

diff --git a/config.def.h b/config.def.h
index 2d3cabf..6d7f690 100644
--- a/config.def.h
+++ b/config.def.h
_AT_@ -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" },
_AT_@ -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
index 7a801a5..c848e81 100644
--- a/http.c
+++ b/http.c
_AT_@ -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
index 06714fb..3075c28 100644
--- a/resp.c
+++ b/resp.c
_AT_@ -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;
Received on Wed Jan 02 2019 - 17:05:36 CET

This archive was generated by hypermail 2.3.0 : Wed Jan 02 2019 - 17:12:23 CET