]> granicus.if.org Git - cgit/commitdiff
plain: don't append charset for binary MIME types
authorJohn Keeping <john@keeping.me.uk>
Sun, 6 Oct 2013 11:14:41 +0000 (12:14 +0100)
committerJason A. Donenfeld <Jason@zx2c4.com>
Wed, 8 Jan 2014 13:59:38 +0000 (14:59 +0100)
When outputting the Content-Type HTTP header we print the MIME type and
then append "; charset=<charset>" if the charset variable is non-null.

We don't want a charset when we have selected "application/octet-stream"
or when the user has specified a custom MIME type, since they may have
specified their own charset.  To avoid this, make sure we set the page's
charset to NULL in ui-plain before we generate the HTTP headers.

Signed-off-by: John Keeping <john@keeping.me.uk>
Signed-off-by: Lukas Fleischer <cgit@cryptocrack.de>
ui-plain.c

index 9c865423fdddd58a0777c50f05c559ea8a277dce..c9ec40338c46999164412839562837d9738ba0ca 100644 (file)
@@ -83,17 +83,22 @@ static int print_object(const unsigned char *sha1, const char *path)
                mime = string_list_lookup(&ctx.cfg.mimetypes, ext);
                if (mime) {
                        ctx.page.mimetype = (char *)mime->util;
+                       ctx.page.charset = NULL;
                } else {
                        ctx.page.mimetype = get_mimetype_from_file(ctx.cfg.mimetype_file, ext);
-                       if (ctx.page.mimetype)
+                       if (ctx.page.mimetype) {
                                freemime = 1;
+                               ctx.page.charset = NULL;
+                       }
                }
        }
        if (!ctx.page.mimetype) {
-               if (buffer_is_binary(buf, size))
+               if (buffer_is_binary(buf, size)) {
                        ctx.page.mimetype = "application/octet-stream";
-               else
+                       ctx.page.charset = NULL;
+               } else {
                        ctx.page.mimetype = "text/plain";
+               }
        }
        ctx.page.filename = path;
        ctx.page.size = size;