James Moger
2014-11-24 b4fbe4fd4430d644d60e8ffcb90370c75a84e540
Ensure that pretty-printed files are served as text/plain in Raw servlet
1 files modified
15 ■■■■ changed files
src/main/java/com/gitblit/servlet/RawServlet.java 15 ●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/servlet/RawServlet.java
@@ -234,9 +234,18 @@
                // 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