[PATCH 2/2] about: send images plain

Christian Hesse list at eworm.de
Fri Aug 14 16:50:57 CEST 2015


From: Christian Hesse <mail at eworm.de>

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 <mail at eworm.de>
---
 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



More information about the CGit mailing list