From 6827fe255ec6b457f0a8382813abd766f52d6632 Mon Sep 17 00:00:00 2001 From: Violeta Georgieva Date: Thu, 2 Mar 2023 12:57:54 +0200 Subject: [PATCH] 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 --- .../http/server/DefaultHttpForwardedHeaderHandler.java | 8 ++++++-- .../reactor/netty/http/server/HttpServerOperations.java | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/reactor-netty-http/src/main/java/reactor/netty/http/server/DefaultHttpForwardedHeaderHandler.java b/reactor-netty-http/src/main/java/reactor/netty/http/server/DefaultHttpForwardedHeaderHandler.java index e3d316d79e..4cd24e7864 100644 --- a/reactor-netty-http/src/main/java/reactor/netty/http/server/DefaultHttpForwardedHeaderHandler.java +++ b/reactor-netty-http/src/main/java/reactor/netty/http/server/DefaultHttpForwardedHeaderHandler.java @@ -69,9 +69,11 @@ private ConnectionInfo parseForwardedInfo(ConnectionInfo connectionInfo, String if (protoMatcher.find()) { connectionInfo = connectionInfo.withScheme(protoMatcher.group(1).trim()); } - int port = connectionInfo.getScheme().equalsIgnoreCase("https") ? DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT; Matcher hostMatcher = FORWARDED_HOST_PATTERN.matcher(forwarded); if (hostMatcher.find()) { + String scheme = connectionInfo.getScheme(); + int port = scheme.equalsIgnoreCase("https") || scheme.equalsIgnoreCase("wss") ? + DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT; connectionInfo = connectionInfo.withHostAddress( AddressUtils.parseAddress(hostMatcher.group(1), port, DEFAULT_FORWARDED_HEADER_VALIDATION)); } @@ -96,7 +98,9 @@ private ConnectionInfo parseXForwardedInfo(ConnectionInfo connectionInfo, HttpRe } String hostHeader = request.headers().get(X_FORWARDED_HOST_HEADER); if (hostHeader != null) { - int port = connectionInfo.getScheme().equalsIgnoreCase("https") ? DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT; + String scheme = connectionInfo.getScheme(); + int port = scheme.equalsIgnoreCase("https") || scheme.equalsIgnoreCase("wss") ? + DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT; connectionInfo = connectionInfo.withHostAddress( AddressUtils.parseAddress(hostHeader.split(",", 2)[0].trim(), port, DEFAULT_FORWARDED_HEADER_VALIDATION)); String portHeader = request.headers().get(X_FORWARDED_PORT_HEADER); diff --git a/reactor-netty-http/src/main/java/reactor/netty/http/server/HttpServerOperations.java b/reactor-netty-http/src/main/java/reactor/netty/http/server/HttpServerOperations.java index acd67d5c8b..2f85d5d264 100644 --- a/reactor-netty-http/src/main/java/reactor/netty/http/server/HttpServerOperations.java +++ b/reactor-netty-http/src/main/java/reactor/netty/http/server/HttpServerOperations.java @@ -490,7 +490,7 @@ public String hostName() { public int hostPort() { return connectionInfo != null ? connectionInfo.getHostPort() : - scheme().equalsIgnoreCase("https") ? DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT; + scheme().equalsIgnoreCase("https") || scheme().equalsIgnoreCase("wss") ? DEFAULT_HTTPS_PORT : DEFAULT_HTTP_PORT; } @Override