Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/jetty-11.0.x' into jetty-12.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
joakime committed Feb 14, 2024
2 parents 0e79997 + b503e17 commit 645e775
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1409,11 +1409,13 @@ public static void appendSchemeHostPort(StringBuilder url, String scheme, String
{
switch (scheme)
{
case "ws":
case "http":
if (port != 80)
url.append(':').append(port);
break;

case "wss":
case "https":
if (port != 443)
url.append(':').append(port);
Expand Down Expand Up @@ -1441,11 +1443,13 @@ public static void appendSchemeHostPort(StringBuffer url, String scheme, String
{
switch (scheme)
{
case "ws":
case "http":
if (port != 80)
url.append(':').append(port);
break;

case "wss":
case "https":
if (port != 443)
url.append(':').append(port);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1185,4 +1185,43 @@ public void testSplitOnPipeWithGlob() throws IOException
};
assertThat(uris, contains(expected));
}

public static Stream<Arguments> appendSchemeHostPortCases()
{
return Stream.of(
// Default behaviors of stripping a port number based on scheme
Arguments.of("http", "example.org", 80, "http://example.org"),
Arguments.of("https", "example.org", 443, "https://example.org"),
Arguments.of("ws", "example.org", 80, "ws://example.org"),
Arguments.of("wss", "example.org", 443, "wss://example.org"),
// Mismatches between scheme and port
Arguments.of("http", "example.org", 443, "http://example.org:443"),
Arguments.of("https", "example.org", 80, "https://example.org:80"),
Arguments.of("ws", "example.org", 443, "ws://example.org:443"),
Arguments.of("wss", "example.org", 80, "wss://example.org:80"),
// Odd ports
Arguments.of("http", "example.org", 12345, "http://example.org:12345"),
Arguments.of("https", "example.org", 54321, "https://example.org:54321"),
Arguments.of("ws", "example.org", 6666, "ws://example.org:6666"),
Arguments.of("wss", "example.org", 7777, "wss://example.org:7777")
);
}

@ParameterizedTest
@MethodSource("appendSchemeHostPortCases")
public void testAppendSchemeHostPortBuilder(String scheme, String server, int port, String expectedStr)
{
StringBuilder actual = new StringBuilder();
URIUtil.appendSchemeHostPort(actual, scheme, server, port);
assertEquals(expectedStr, actual.toString());
}

@ParameterizedTest
@MethodSource("appendSchemeHostPortCases")
public void testAppendSchemeHostPortBuffer(String scheme, String server, int port, String expectedStr)
{
StringBuffer actual = new StringBuffer();
URIUtil.appendSchemeHostPort(actual, scheme, server, port);
assertEquals(expectedStr, actual.toString());
}
}

0 comments on commit 645e775

Please sign in to comment.