about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJohn Keeping <john@keeping.me.uk>2013-10-06 12:14:41 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2014-01-08 14:59:38 +0100
commit407f71cc061564d63b7358dd36a5bfebda05b15a (patch)
tree9691450ae35a95e27fe0ff9d782a84675cad7681
parentui-log.c: Several simplifications (diff)
downloadcgit-pink-407f71cc061564d63b7358dd36a5bfebda05b15a.tar.gz
cgit-pink-407f71cc061564d63b7358dd36a5bfebda05b15a.zip
plain: don't append charset for binary MIME types
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>
-rw-r--r--ui-plain.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/ui-plain.c b/ui-plain.c
index 9c86542..c9ec403 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -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;
>June McEnroe 2018-03-31Link against ncursesJune McEnroe 2018-03-05Miscellaneous code cleanupJune McEnroe 2018-03-05Pass message structs by valueJune McEnroe 2018-03-05Use stdio in merge and metaJune McEnroe 2018-03-05Clean up spawn constantsJune McEnroe 2018-03-05Rename Tile timestamps {create,modify,access}TimeJune McEnroe 2018-03-05Pack message type enumsJune McEnroe 2018-03-05Undef COLOR_ constants in torus.hJune McEnroe 2018-03-05Generate tagsJune McEnroe 2017-10-03Simplify Makefile with pattern ruleJune McEnroe 2017-09-27Remove leading blank linesJune McEnroe 2017-09-27Add merge.c to READMEJune McEnroe 2017-09-03Assert client coords are valid after movementJune McEnroe 2017-09-03Relicense AGPLJune McEnroe 2017-09-01Revert "Add client readOnly mode"June McEnroe 2017-09-01Remove clientRemove call from clientCastJune McEnroe 2017-09-01Add client readOnly modeJune McEnroe 2017-08-31Clean up merge toolJune McEnroe 2017-08-31Choose B for tiles with equal modify timesJune McEnroe 2017-08-31Add quick data file merge toolJune McEnroe 2017-08-30Use only foreground color for selecting spawnJune McEnroe 2017-08-29Add four additional spawnsJune McEnroe 2017-08-28Add respawningJune McEnroe 2017-08-26Move license above includesJune McEnroe 2017-08-26Snapshot metadataJune McEnroe 2017-08-26Add meta.c to READMEJune McEnroe 2017-08-26Use MakefileJune McEnroe