diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Send a charset only with a text type
Archives, packs and the HEAD file went out as octet-stream or gzip
with a UTF-8 charset on the end, since only the blob page cleared it.
The headers now decide from the type itself, so the two places that
cleared the charset by hand no longer need to.
Diffstat (limited to 'source/ui-shared.c')
| -rw-r--r-- | source/ui-shared.c | 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 12 insertions, 1 deletion
diff --git a/source/ui-shared.c b/source/ui-shared.c index 3970c58..a112fb2 100644 --- a/source/ui-shared.c +++ b/source/ui-shared.c @@ -1424,6 +1424,15 @@ void cgit_print_age(time_t t, int tz, time_t max_relative) print_rel_date(t, tz, secs * 1.0 / SECONDS_PER_YEAR, "age-years", "years"); } +/* + * Whether a content type carries text a charset applies to, which is every + * text type and the XML ones, the atom feed among them. + */ +static int type_has_charset(const char *mimetype) +{ + return starts_with(mimetype, "text/") || strstr(mimetype, "xml"); +} + void cgit_print_http_headers(void) { ctx.page.headers_sent = 1; @@ -1436,7 +1445,9 @@ void cgit_print_http_headers(void) htmlf("Status: %d %s\n", ctx.page.status, ctx.page.statusmsg); else html("Status: 200 OK\n"); - if (ctx.page.mimetype && ctx.page.charset) + // A charset only means something for text, so an archive or a pack + // is sent without one. + if (ctx.page.mimetype && ctx.page.charset && type_has_charset(ctx.page.mimetype)) htmlf("Content-Type: %s; charset=%s\n", ctx.page.mimetype, ctx.page.charset); else if (ctx.page.mimetype) htmlf("Content-Type: %s\n", ctx.page.mimetype); |
