diff options
author | James Moger <james.moger@gmail.com> | 2016-06-13 14:14:06 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-06-13 14:14:06 -0400 |
commit | 24d577fd683cf5158ef5409a6fa0b7030977b18b (patch) | |
tree | 17228e86d05b7ee0a8ba6eea35100f39915da83c /src/main | |
parent | a502d96a860456ec5e8c96761db70f7cabb74751 (diff) | |
parent | a1ef8e93062c58d4eace2c6598953e1d350d3fcc (diff) | |
download | gitblit-24d577fd683cf5158ef5409a6fa0b7030977b18b.tar.gz gitblit-24d577fd683cf5158ef5409a6fa0b7030977b18b.zip |
Merge pull request #1086 from dsteinkopf/master
fix baseURL handling in HttpUtils, fixes #1083
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/com/gitblit/utils/HttpUtils.java | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/main/java/com/gitblit/utils/HttpUtils.java b/src/main/java/com/gitblit/utils/HttpUtils.java index 818ed492..2fd8d898 100644 --- a/src/main/java/com/gitblit/utils/HttpUtils.java +++ b/src/main/java/com/gitblit/utils/HttpUtils.java @@ -78,6 +78,7 @@ public class HttpUtils { }
}
+ // try to use reverse-proxy's context
String context = request.getContextPath();
String forwardedContext = request.getHeader("X-Forwarded-Context");
if (StringUtils.isEmpty(forwardedContext)) {
@@ -92,13 +93,24 @@ public class HttpUtils { context = context.substring(1);
}
+ // try to use reverse-proxy's hostname
+ String host = request.getServerName();
+ String forwardedHost = request.getHeader("X-Forwarded-Host");
+ if (StringUtils.isEmpty(forwardedHost)) {
+ forwardedHost = request.getHeader("X_Forwarded_Host");
+ }
+ if (!StringUtils.isEmpty(forwardedHost)) {
+ host = forwardedHost;
+ }
+
+ // build result
StringBuilder sb = new StringBuilder();
sb.append(scheme);
sb.append("://");
- sb.append(request.getServerName());
+ sb.append(host);
if (("http".equals(scheme) && port != 80)
|| ("https".equals(scheme) && port != 443)) {
- sb.append(":" + port);
+ sb.append(":").append(port);
}
sb.append(context);
return sb.toString();
|