diff options
author | James Moger <james.moger@gitblit.com> | 2013-10-16 09:29:42 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2013-10-16 09:30:46 -0400 |
commit | 9996f7217ea381d8e23755b3036f052cbdce6f3a (patch) | |
tree | 210712e5061087a108d5a68e0b21c0e729dd44e9 /src | |
parent | c95e30cd57ab33c1ffe1d6cd00259a638c6fed38 (diff) | |
download | gitblit-9996f7217ea381d8e23755b3036f052cbdce6f3a.tar.gz gitblit-9996f7217ea381d8e23755b3036f052cbdce6f3a.zip |
Fix raw page binary content type when running behind reverse proxy
Change-Id: I9f613114b2bb4c1dacae6e67c7673149a0476cf1
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/com/gitblit/wicket/pages/RawPage.java | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/main/java/com/gitblit/wicket/pages/RawPage.java b/src/main/java/com/gitblit/wicket/pages/RawPage.java index 50268717..17837649 100644 --- a/src/main/java/com/gitblit/wicket/pages/RawPage.java +++ b/src/main/java/com/gitblit/wicket/pages/RawPage.java @@ -44,6 +44,8 @@ public class RawPage extends SessionPage { private final Logger logger = LoggerFactory.getLogger(getClass().getSimpleName());
+ String contentType;
+
public RawPage(final PageParameters params) {
super(params);
@@ -86,7 +88,8 @@ public class RawPage extends SessionPage { 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 @@ public class RawPage extends SessionPage { 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 @@ public class RawPage extends SessionPage { 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 @@ public class RawPage extends SessionPage { // 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 @@ public class RawPage extends SessionPage { // 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 @@ public class RawPage extends SessionPage { }
});
}
+
+ @Override
+ protected void setHeaders(WebResponse response) {
+ super.setHeaders(response);
+ if (!StringUtils.isEmpty(contentType)) {
+ response.setContentType(contentType);
+ }
+ }
}
|