diff --git a/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java b/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java index 95fcfea142fb..be00b41d00c6 100644 --- a/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java +++ b/jetty-core/jetty-http/src/test/java/org/eclipse/jetty/http/HttpURITest.java @@ -1109,6 +1109,8 @@ public static Stream concatNormalizedURICases() Arguments.of("hTTps", "example.org", 443, "/", null, null, "https://example.org/"), Arguments.of("WS", "example.org", 8282, "/", null, null, "ws://example.org:8282/"), Arguments.of("wsS", "example.org", 8383, "/", null, null, "wss://example.org:8383/"), + // Undefined scheme + Arguments.of(null, "example.org", 8181, "/", null, null, "//example.org:8181/"), // Undefined Ports Arguments.of("http", "example.org", 0, "/", null, null, "http://example.org/"), Arguments.of("https", "example.org", -1, "/", null, null, "https://example.org/"), diff --git a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index 0673d9160167..aa494c761ec1 100644 --- a/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-core/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -486,9 +486,13 @@ static int getServerPort(Request request) return authority.getPort(); // Is there a scheme with a default port? - HttpScheme scheme = HttpScheme.CACHE.get(request.getHttpURI().getScheme()); - if (scheme != null && scheme.getDefaultPort() > 0) - return scheme.getDefaultPort(); + String rawScheme = uri.getScheme(); + if (StringUtil.isNotBlank(rawScheme)) + { + HttpScheme scheme = HttpScheme.CACHE.get(rawScheme); + if (scheme != null && scheme.getDefaultPort() > 0) + return scheme.getDefaultPort(); + } // Is there a local port? SocketAddress local = request.getConnectionMetaData().getLocalSocketAddress();