Skip to content

Commit

Permalink
Update GrailsWebRequest
Browse files Browse the repository at this point in the history
to read the PORT information from the request header when it is missing
in the request. This fixes #12816 where application is accesed via
AWS's ALB.
  • Loading branch information
puneetbehl committed Nov 6, 2023
1 parent 82181d6 commit 648a0b6
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 648a0b6

Please sign in to comment.