From 5cc0a69a7be2af8bb11ccee3e3ea2624904c4fa0 Mon Sep 17 00:00:00 2001 From: James Moger Date: Fri, 22 May 2015 14:08:30 -0400 Subject: [PATCH] Fix html raw content type serving --- .../java/com/gitblit/servlet/RawServlet.java | 27 ++++++++++++------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/gitblit/servlet/RawServlet.java b/src/main/java/com/gitblit/servlet/RawServlet.java index 16d1a977..09f9f8a3 100644 --- a/src/main/java/com/gitblit/servlet/RawServlet.java +++ b/src/main/java/com/gitblit/servlet/RawServlet.java @@ -24,6 +24,7 @@ import java.text.MessageFormat; import java.text.ParseException; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.TreeMap; @@ -228,23 +229,31 @@ public class RawServlet extends HttpServlet { return; } + Map quickContentTypes = new HashMap<>(); + quickContentTypes.put("html", "text/html"); + quickContentTypes.put("htm", "text/html"); + quickContentTypes.put("xml", "application/xml"); + quickContentTypes.put("json", "application/json"); List pathEntries = JGitUtils.getFilesInPath(r, requestedPath, commit); if (pathEntries.isEmpty()) { // requested a specific resource String file = StringUtils.getLastPathElement(requestedPath); try { - String contentType; - List exts = runtimeManager.getSettings().getStrings(Keys.web.prettyPrintExtensions); String ext = StringUtils.getFileExtension(file).toLowerCase(); - if (exts.contains(ext)) { - // extension is a registered text type for pretty printing - contentType = "text/plain"; - } else { - // query Tika for the content type - Tika tika = new Tika(); - contentType = tika.detect(file); + String contentType = quickContentTypes.get(ext); + + if (contentType == null) { + List exts = runtimeManager.getSettings().getStrings(Keys.web.prettyPrintExtensions); + if (exts.contains(ext)) { + // extension is a registered text type for pretty printing + contentType = "text/plain"; + } else { + // query Tika for the content type + Tika tika = new Tika(); + contentType = tika.detect(file); + } } if (contentType == null) { -- 2.39.5