James Moger
2013-10-16 9996f7217ea381d8e23755b3036f052cbdce6f3a
Fix raw page binary content type when running behind reverse proxy

Change-Id: I9f613114b2bb4c1dacae6e67c7673149a0476cf1
2 files modified
26 ■■■■ changed files
releases.moxie 1 ●●●● patch | view | raw | blame | history
src/main/java/com/gitblit/wicket/pages/RawPage.java 25 ●●●● patch | view | raw | blame | history
releases.moxie
@@ -14,6 +14,7 @@
    - Fix potential NPE on removing uncached repository from cache
    - Ignore the default contents of .git/description file
    - Fix error on generating activity page when there is no activity
    - Fix raw page content type of binaries when running behind a reverse proxy
    changes:
    - Personal repository prefix (~) is now configurable (issue-265)
    - Reversed line links in blob view (issue-309)
src/main/java/com/gitblit/wicket/pages/RawPage.java
@@ -44,6 +44,8 @@
    private final Logger logger = LoggerFactory.getLogger(getClass().getSimpleName());
    String contentType;
    public RawPage(final PageParameters params) {
        super(params);
@@ -86,7 +88,8 @@
                if (StringUtils.isEmpty(blobPath)) {
                    // objectid referenced raw view
                    byte [] binary = JGitUtils.getByteContent(r, objectId);
                    response.setContentType("application/octet-stream");
                    contentType = "application/octet-stream";
                    response.setContentType(contentType);
                    response.setContentLength(binary.length);
                    try {
                        response.getOutputStream().write(binary);
@@ -125,7 +128,8 @@
                        case 2:
                            // image blobs
                            byte[] image = JGitUtils.getByteContent(r, commit.getTree(), blobPath, true);
                            response.setContentType("image/" + extension.toLowerCase());
                            contentType = "image/" + extension.toLowerCase();
                            response.setContentType(contentType);
                            response.setContentLength(image.length);
                            try {
                                response.getOutputStream().write(image);
@@ -136,8 +140,9 @@
                        case 3:
                            // binary blobs (download)
                            byte[] binary = JGitUtils.getByteContent(r, commit.getTree(), blobPath, true);
                            contentType = "application/octet-stream";
                            response.setContentLength(binary.length);
                            response.setContentType("application/octet-stream; charset=UTF-8");
                            response.setContentType(contentType);
                            try {
                                WebRequest request = (WebRequest) requestCycle.getRequest();
@@ -168,7 +173,8 @@
                            // plain text
                            String content = JGitUtils.getStringContent(r, commit.getTree(),
                                    blobPath, encodings);
                            response.setContentType("text/plain; charset=UTF-8");
                            contentType = "text/plain; charset=UTF-8";
                            response.setContentType(contentType);
                            try {
                                response.getOutputStream().write(content.getBytes("UTF-8"));
                            } catch (Exception e) {
@@ -180,7 +186,8 @@
                        // plain text
                        String content = JGitUtils.getStringContent(r, commit.getTree(), blobPath,
                                encodings);
                        response.setContentType("text/plain; charset=UTF-8");
                        contentType = "text/plain; charset=UTF-8";
                        response.setContentType(contentType);
                        try {
                            response.getOutputStream().write(content.getBytes("UTF-8"));
                        } catch (Exception e) {
@@ -192,4 +199,12 @@
            }
        });
    }
    @Override
    protected void setHeaders(WebResponse response) {
        super.setHeaders(response);
        if (!StringUtils.isEmpty(contentType)) {
            response.setContentType(contentType);
        }
    }
}