Skip to content

Commit

Permalink
Merge pull request #13197 from grails/12816-read-port-from-header
Browse files Browse the repository at this point in the history
Update GrailsWebRequest
  • Loading branch information
puneetbehl authored Nov 6, 2023
2 parents d8d8917 + 648a0b6 commit bb9e61a
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,17 @@ public String getBaseUrl() {
sb.append(scheme).append("://").append(request.getServerName());

int port = request.getServerPort();

String forwardedPort = request.getHeader("X-Forwarded-Port");

//ignore port append if the request was forwarded from a VIP as actual source port is now not known
if (forwardedScheme == null && (("http".equals(scheme) && port != 80) || ("https".equals(scheme) && port != 443))) {
sb.append(":").append(port);
} else if (forwardedPort != null &&
("http".equals(forwardedScheme) && !"80".equals(forwardedPort)) ||
("https".equals(forwardedScheme) && !"443".equals(forwardedPort))) {
sb.append(":").append(forwardedPort);
}

String contextPath = request.getContextPath();
if (contextPath != null) {
sb.append(contextPath);
Expand Down

0 comments on commit bb9e61a

Please sign in to comment.