summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2012-09-20 09:41:28 -0400
committerJames Moger <james.moger@gitblit.com>2012-09-20 09:41:28 -0400
commitc558deef274d838aae5c0366ff7dc2ebce27a981 (patch)
tree33b0b6ec6183fcf5c676168659fe87185e1d0876
parent33622b7acfa037d0218dd7a9d62b4831015768f3 (diff)
downloadgitblit-c558deef274d838aae5c0366ff7dc2ebce27a981.tar.gz
gitblit-c558deef274d838aae5c0366ff7dc2ebce27a981.zip
Support X-Forwarded-Context for subdomain proxy configs (issue 135)
-rw-r--r--docs/01_setup.mkd5
-rw-r--r--docs/04_releases.mkd1
-rw-r--r--src/com/gitblit/utils/HttpUtils.java16
3 files changed, 21 insertions, 1 deletions
diff --git a/docs/01_setup.mkd b/docs/01_setup.mkd
index eaaf3be5..fa1bcd90 100644
--- a/docs/01_setup.mkd
+++ b/docs/01_setup.mkd
@@ -161,6 +161,11 @@ ProxyPreserveHost On
#RequestHeader set X-Forwarded-Proto https
#RequestHeader set X-Forwarded-Port 443
+# If you are using subdomain proxying then you will want to tell Gitblit the appropriate
+# context path for your repository url.
+# If you are not using subdomain proxying, then ignore this setting.
+#RequestHeader set X-Forwarded-Context /
+
#ProxyPass /gitblit ajp://localhost:8009/gitblit
%ENDCODE%
**Please** make sure to:
diff --git a/docs/04_releases.mkd b/docs/04_releases.mkd
index 271e18a7..7f0feece 100644
--- a/docs/04_releases.mkd
+++ b/docs/04_releases.mkd
@@ -16,6 +16,7 @@ If you are updating from an earlier release AND you have indexed branches with t
#### additions
+- added support for X-Forwarded-Context for Apache subdomain proxy configurations (issue 135)
- delete branch feature (issue 121, Github/ajermakovics)
- added line links to blob view at the expense of zebra striping (issue 130)
- added RedmineUserService (github/mallowlabs)
diff --git a/src/com/gitblit/utils/HttpUtils.java b/src/com/gitblit/utils/HttpUtils.java
index 3903f8c7..ad7d58c1 100644
--- a/src/com/gitblit/utils/HttpUtils.java
+++ b/src/com/gitblit/utils/HttpUtils.java
@@ -67,6 +67,20 @@ public class HttpUtils {
}
}
+ String context = request.getContextPath();
+ String forwardedContext = request.getHeader("X-Forwarded-Context");
+ if (forwardedContext != null) {
+ forwardedContext = request.getHeader("X_Forwarded_Context");
+ }
+ if (!StringUtils.isEmpty(forwardedContext)) {
+ context = forwardedContext;
+ }
+
+ // trim any trailing slash
+ if (context.length() > 0 && context.charAt(context.length() - 1) == '/') {
+ context = context.substring(1);
+ }
+
StringBuilder sb = new StringBuilder();
sb.append(scheme);
sb.append("://");
@@ -75,7 +89,7 @@ public class HttpUtils {
|| ("https".equals(scheme) && port != 443)) {
sb.append(":" + port);
}
- sb.append(request.getContextPath());
+ sb.append(context);
return sb.toString();
}
}