}\r
}\r
\r
+ // try to use reverse-proxy's context\r
String context = request.getContextPath();\r
String forwardedContext = request.getHeader("X-Forwarded-Context");\r
if (StringUtils.isEmpty(forwardedContext)) {\r
context = context.substring(1);\r
}\r
\r
+ // try to use reverse-proxy's hostname\r
+ String host = request.getServerName();\r
+ String forwardedHost = request.getHeader("X-Forwarded-Host");\r
+ if (StringUtils.isEmpty(forwardedHost)) {\r
+ forwardedHost = request.getHeader("X_Forwarded_Host");\r
+ }\r
+ if (!StringUtils.isEmpty(forwardedHost)) {\r
+ host = forwardedHost;\r
+ }\r
+\r
+ // build result\r
StringBuilder sb = new StringBuilder();\r
sb.append(scheme);\r
sb.append("://");\r
- sb.append(request.getServerName());\r
+ sb.append(host);\r
if (("http".equals(scheme) && port != 80)\r
|| ("https".equals(scheme) && port != 443)) {\r
- sb.append(":" + port);\r
+ sb.append(":").append(port);\r
}\r
sb.append(context);\r
return sb.toString();\r