file: specify UTF-8 as charset for dirlists, add option to override
authorJo-Philipp Wich <jo@mein.io>
Tue, 21 Dec 2021 09:30:35 +0000 (10:30 +0100)
committerJo-Philipp Wich <jo@mein.io>
Mon, 7 Feb 2022 08:59:21 +0000 (09:59 +0100)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
file.c
main.c
uhttpd.h

diff --git a/file.c b/file.c
index 85487f8e14d666cf913e8dae79a7ea3e5e4d35fa..15489007e460f1ed1cec27921d1276a2c5d9a0e7 100644 (file)
--- a/file.c
+++ b/file.c
@@ -546,7 +546,8 @@ static void uh_file_dirlist(struct client *cl, struct path_info *pi)
        }
 
        uh_file_response_200(cl, NULL);
-       ustream_printf(cl->us, "Content-Type: text/html\r\n\r\n");
+       ustream_printf(cl->us, "Content-Type: text/html; charset=%s\r\n\r\n",
+               conf.dirlist_charset ? conf.dirlist_charset : "UTF-8");
 
        uh_chunk_printf(cl,
                "<html><head><title>Index of %s</title></head>"
diff --git a/main.c b/main.c
index 893350a2323fca1aaa91a2a3662dac55582d4ae0..d1aac09c355206b25674319f75ef8f99399caf4b 100644 (file)
--- a/main.c
+++ b/main.c
@@ -144,6 +144,7 @@ static int usage(const char *name)
 #endif
                "       -h directory    Specify the document root, default is '.'\n"
                "       -E string       Use given virtual URL as 404 error handler\n"
+               "       -b string       Use given charset for directory listings, default to UTF-8\n"
                "       -I string       Use given filename as index for directories, multiple allowed\n"
                "       -S              Do not follow symbolic links outside of the docroot\n"
                "       -D              Do not allow directory listings, send 403 instead\n"
@@ -292,7 +293,7 @@ int main(int argc, char **argv)
        init_defaults_pre();
        signal(SIGPIPE, SIG_IGN);
 
-       while ((ch = getopt(argc, argv, "A:aC:c:Dd:E:e:fh:H:I:i:K:k:L:l:m:N:n:O:o:P:p:qRr:Ss:T:t:U:u:Xx:y:")) != -1) {
+       while ((ch = getopt(argc, argv, "A:ab:C:c:Dd:E:e:fh:H:I:i:K:k:L:l:m:N:n:O:o:P:p:qRr:Ss:T:t:U:u:Xx:y:")) != -1) {
                switch(ch) {
 #ifdef HAVE_TLS
                case 'C':
@@ -364,6 +365,10 @@ int main(int argc, char **argv)
                        uh_index_add(optarg);
                        break;
 
+               case 'b':
+                       conf.dirlist_charset = optarg;
+                       break;
+
                case 'S':
                        conf.no_symlinks = 1;
                        break;
index d230b31343cfbcaa15dc8e60803c275078988283..c755df6a70bf0be74f2cfffb85a2fadf306024df 100644 (file)
--- a/uhttpd.h
+++ b/uhttpd.h
@@ -81,6 +81,7 @@ struct config {
        const char *cgi_path;
        const char *ubus_prefix;
        const char *ubus_socket;
+       const char *dirlist_charset;
        int no_symlinks;
        int no_dirlists;
        int network_timeout;