List for cgit developers and users
 help / color / mirror / Atom feed
From: john at keeping.me.uk (John Keeping)
Subject: [PATCH] plain: don't append charset for binary MIME types
Date: Sun,  6 Oct 2013 12:14:41 +0100	[thread overview]
Message-ID: <302d303041d2a118a33185433ec147f15c32154a.1381058081.git.john@keeping.me.uk> (raw)

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 at keeping.me.uk>
---
 ui-plain.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/ui-plain.c b/ui-plain.c
index 9c86542..23a2b6d 100644
--- a/ui-plain.c
+++ b/ui-plain.c
@@ -83,16 +83,20 @@ 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;
-- 
1.8.4.566.g73d370b



                 reply	other threads:[~2013-10-06 11:14 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=302d303041d2a118a33185433ec147f15c32154a.1381058081.git.john@keeping.me.uk \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).