diff options
author | James Moger <james.moger@gitblit.com> | 2014-11-24 09:34:27 -0500 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2014-11-24 09:34:27 -0500 |
commit | b4fbe4fd4430d644d60e8ffcb90370c75a84e540 (patch) | |
tree | 6f0ba0b6f17c1fd34447d1875c021d4944ab0fdc | |
parent | a1b5df7c1861cf2b2f97dc9339e3155e176d0cf8 (diff) | |
download | gitblit-b4fbe4fd4430d644d60e8ffcb90370c75a84e540.tar.gz gitblit-b4fbe4fd4430d644d60e8ffcb90370c75a84e540.zip |
Ensure that pretty-printed files are served as text/plain in Raw servlet
-rw-r--r-- | src/main/java/com/gitblit/servlet/RawServlet.java | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/main/java/com/gitblit/servlet/RawServlet.java b/src/main/java/com/gitblit/servlet/RawServlet.java index dac38f36..16d1a977 100644 --- a/src/main/java/com/gitblit/servlet/RawServlet.java +++ b/src/main/java/com/gitblit/servlet/RawServlet.java @@ -234,9 +234,18 @@ public class RawServlet extends HttpServlet { // requested a specific resource String file = StringUtils.getLastPathElement(requestedPath); try { - // query Tika for the content type - Tika tika = new Tika(); - String contentType = tika.detect(file); + 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); + } if (contentType == null) { // ask the container for the content type |