diff options
author | James Moger <james.moger@gitblit.com> | 2015-05-22 14:08:30 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2015-05-22 14:08:30 -0400 |
commit | 5cc0a69a7be2af8bb11ccee3e3ea2624904c4fa0 (patch) | |
tree | 1695a9284209d83d322012b48da6dfd16e475adc /src/main/java/com/gitblit | |
parent | a89679ebd62d5b524b8e6a11a2a6eccc2774e1a3 (diff) | |
download | gitblit-5cc0a69a7be2af8bb11ccee3e3ea2624904c4fa0.tar.gz gitblit-5cc0a69a7be2af8bb11ccee3e3ea2624904c4fa0.zip |
Fix html raw content type serving
Diffstat (limited to 'src/main/java/com/gitblit')
-rw-r--r-- | src/main/java/com/gitblit/servlet/RawServlet.java | 27 |
1 files 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<String, String> quickContentTypes = new HashMap<>(); + quickContentTypes.put("html", "text/html"); + quickContentTypes.put("htm", "text/html"); + quickContentTypes.put("xml", "application/xml"); + quickContentTypes.put("json", "application/json"); List<PathModel> pathEntries = JGitUtils.getFilesInPath(r, requestedPath, commit); if (pathEntries.isEmpty()) { // requested a specific resource String file = StringUtils.getLastPathElement(requestedPath); try { - String contentType; - List<String> 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<String> 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) { |