Skip to content

Commit 5990ca8

Browse files
authored
When the scheme is https/wss, the https default port is used as a fallback option (#2715)
This change is in addition to PR #2714
1 parent 005e6df commit 5990ca8

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

reactor-netty-http/src/main/java/reactor/netty/http/server/DefaultHttpForwardedHeaderHandler.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,11 @@ private ConnectionInfo parseForwardedInfo(ConnectionInfo connectionInfo, String
6969
if (protoMatcher.find()) {
7070
connectionInfo = connectionInfo.withScheme(protoMatcher.group(1).trim());
7171
}
72-
int port = connectionInfo.getScheme().equalsIgnoreCase("https") ? DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT;
7372
Matcher hostMatcher = FORWARDED_HOST_PATTERN.matcher(forwarded);
7473
if (hostMatcher.find()) {
74+
String scheme = connectionInfo.getScheme();
75+
int port = scheme.equalsIgnoreCase("https") || scheme.equalsIgnoreCase("wss") ?
76+
DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT;
7577
connectionInfo = connectionInfo.withHostAddress(
7678
AddressUtils.parseAddress(hostMatcher.group(1), port, DEFAULT_FORWARDED_HEADER_VALIDATION));
7779
}
@@ -96,7 +98,9 @@ private ConnectionInfo parseXForwardedInfo(ConnectionInfo connectionInfo, HttpRe
9698
}
9799
String hostHeader = request.headers().get(X_FORWARDED_HOST_HEADER);
98100
if (hostHeader != null) {
99-
int port = connectionInfo.getScheme().equalsIgnoreCase("https") ? DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT;
101+
String scheme = connectionInfo.getScheme();
102+
int port = scheme.equalsIgnoreCase("https") || scheme.equalsIgnoreCase("wss") ?
103+
DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT;
100104
connectionInfo = connectionInfo.withHostAddress(
101105
AddressUtils.parseAddress(hostHeader.split(",", 2)[0].trim(), port, DEFAULT_FORWARDED_HEADER_VALIDATION));
102106
String portHeader = request.headers().get(X_FORWARDED_PORT_HEADER);

reactor-netty-http/src/main/java/reactor/netty/http/server/HttpServerOperations.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ public String hostName() {
490490
public int hostPort() {
491491
return connectionInfo != null ?
492492
connectionInfo.getHostPort() :
493-
scheme().equalsIgnoreCase("https") ? DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT;
493+
scheme().equalsIgnoreCase("https") || scheme().equalsIgnoreCase("wss") ? DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT;
494494
}
495495

496496
@Override

0 commit comments

Comments
 (0)