]> source.dussan.org Git - gitblit.git/commitdiff
Support X-Forwarded-Context for subdomain proxy configs (issue 135)
authorJames Moger <james.moger@gitblit.com>
Thu, 20 Sep 2012 13:41:28 +0000 (09:41 -0400)
committerJames Moger <james.moger@gitblit.com>
Thu, 20 Sep 2012 13:41:28 +0000 (09:41 -0400)
docs/01_setup.mkd
docs/04_releases.mkd
src/com/gitblit/utils/HttpUtils.java

index eaaf3be57a071b7fa4a315be6317a60b59a1dbfd..fa1bcd908c2cb0e1e48aaba2db2bb7fcfd7db939 100644 (file)
@@ -161,6 +161,11 @@ ProxyPreserveHost On
 #RequestHeader set X-Forwarded-Proto https\r
 #RequestHeader set X-Forwarded-Port 443\r
 \r
+# If you are using subdomain proxying then you will want to tell Gitblit the appropriate\r
+# context path for your repository url.\r
+# If you are not using subdomain proxying, then ignore this setting.\r
+#RequestHeader set X-Forwarded-Context /\r
+\r
 #ProxyPass /gitblit ajp://localhost:8009/gitblit\r
 %ENDCODE%  \r
 **Please** make sure to:  \r
index 271e18a7e4df95aae49aabaeed595f64d93638b7..7f0feece918df1c3064c7a8f7e621b003d91738b 100644 (file)
@@ -16,6 +16,7 @@ If you are updating from an earlier release AND you have indexed branches with t
 \r
 #### additions\r
 \r
+- added support for X-Forwarded-Context for Apache subdomain proxy configurations (issue 135)\r
 - delete branch feature (issue 121, Github/ajermakovics)\r
 - added line links to blob view at the expense of zebra striping (issue 130)\r
 - added RedmineUserService (github/mallowlabs)\r
index 3903f8c73ec0d1a4efc1b53fe6ab347b44986c1d..ad7d58c1f1ba8668c6b1682d3528df78dee29726 100644 (file)
@@ -67,6 +67,20 @@ public class HttpUtils {
                }\r
         }\r
         \r
+        String context = request.getContextPath();\r
+        String forwardedContext = request.getHeader("X-Forwarded-Context");\r
+        if (forwardedContext != null) {\r
+               forwardedContext = request.getHeader("X_Forwarded_Context");\r
+        }\r
+        if (!StringUtils.isEmpty(forwardedContext)) {\r
+               context = forwardedContext;\r
+        }\r
+        \r
+        // trim any trailing slash\r
+        if (context.length() > 0 && context.charAt(context.length() - 1) == '/') {\r
+               context = context.substring(1);\r
+        }\r
+        \r
                StringBuilder sb = new StringBuilder();\r
                sb.append(scheme);\r
                sb.append("://");\r
@@ -75,7 +89,7 @@ public class HttpUtils {
                                || ("https".equals(scheme) && port != 443)) {\r
                        sb.append(":" + port);\r
                }\r
-               sb.append(request.getContextPath());\r
+               sb.append(context);\r
                return sb.toString();\r
        }\r
 }\r