James Moger
2012-09-20 c558deef274d838aae5c0366ff7dc2ebce27a981
Support X-Forwarded-Context for subdomain proxy configs (issue-135)
3 files modified
22 ■■■■■ changed files
docs/01_setup.mkd 5 ●●●●● patch | view | raw | blame | history
docs/04_releases.mkd 1 ●●●● patch | view | raw | blame | history
src/com/gitblit/utils/HttpUtils.java 16 ●●●●● patch | view | raw | blame | history
docs/01_setup.mkd
@@ -161,6 +161,11 @@
#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:  
docs/04_releases.mkd
@@ -16,6 +16,7 @@
#### 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)
src/com/gitblit/utils/HttpUtils.java
@@ -67,6 +67,20 @@
            }
        }
        
        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 @@
                || ("https".equals(scheme) && port != 443)) {
            sb.append(":" + port);
        }
        sb.append(request.getContextPath());
        sb.append(context);
        return sb.toString();
    }
}