From mboxrd@z Thu Jan 1 00:00:00 1970 From: list at eworm.de (Christian Hesse) Date: Fri, 14 Aug 2015 16:50:57 +0200 Subject: [PATCH 2/2] about: send images plain In-Reply-To: <1439563857-32527-1-git-send-email-list@eworm.de> References: <1439563857-32527-1-git-send-email-list@eworm.de> Message-ID: <1439563857-32527-2-git-send-email-list@eworm.de> From: Christian Hesse The about page used to display just fine, but images were broken: The binary image data was embedded in html code. Use cgit_print_plain() to send images in plain mode and make them available on about page. Signed-off-by: Christian Hesse --- cmd.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/cmd.c b/cmd.c index 20c80b0..d77ee63 100644 --- a/cmd.c +++ b/cmd.c @@ -43,8 +43,37 @@ static void about_fn(void) ctx.qry.url[strlen(ctx.qry.url) - 1] != '/' && ctx.env.path_info[strlen(ctx.env.path_info) - 1] != '/') cgit_redirect(fmtalloc("%s/", cgit_currenturl()), true); - else - cgit_print_repo_readme(ctx.qry.path); + else { + char *ext = NULL; + int freemime = 0; + struct string_list_item *mime; + char * mimetype = NULL; + + if (ctx.qry.path) + ext = strrchr(ctx.qry.path, '.'); + + if (ext && *(++ext)) { + mime = string_list_lookup(&ctx.cfg.mimetypes, ext); + if (mime) { + mimetype = (char *)mime->util; + } else { + mimetype = get_mimetype_from_file(ctx.cfg.mimetype_file, ext); + if (mimetype) + freemime = 1; + } + } + + if (mimetype && strncmp(mimetype, "image/", 6) == 0) { + ctx.page.mimetype = mimetype; + ctx.page.charset = NULL; + cgit_print_plain(); + } else + cgit_print_repo_readme(ctx.qry.path); + + /* If we allocated this, then casting away const is safe. */ + if (freemime) + free(mimetype); + } } else cgit_print_site_readme(); } -- 2.5.0