Skip to content

Commit e4f8ae0

Browse files
committed
Stop setting local port in HtmlUnitRequestBuilder
This commit picks up where commit a0baeae left off. Specifically, in order to align with the behavior of AbstractMockHttpServletRequestBuilder, HtmlUnitRequestBuilder no longer sets the local port in the MockHttpServletRequest. See gh-35709
1 parent e85afff commit e4f8ae0

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,6 @@ private void ports(UriComponents uriComponents, MockHttpServletRequest request)
216216
}
217217
if (serverPort != -1) {
218218
request.setServerPort(serverPort);
219-
request.setLocalPort(serverPort);
220219
}
221220
}
222221

spring-test/src/test/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilderTests.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -897,11 +897,12 @@ private String getContextPath() {
897897
private static void assertUrlAndPorts(HttpServletRequest request, String url, int serverPort, boolean secure) {
898898
assertThat(request.getRequestURL()).asString().as("url").isEqualTo(url);
899899
assertThat(request.getServerPort()).as("server port").isEqualTo(serverPort);
900-
// In a mocked request, the local port is always the same as the server port.
901-
assertThat(request.getLocalPort()).as("local port").isEqualTo(serverPort);
902-
// Remote port is always 80 (MockHttpServletRequest.DEFAULT_SERVER_PORT),
900+
// Local port is always MockHttpServletRequest.DEFAULT_SERVER_PORT,
901+
// since a mocked request does not influence the local port.
902+
assertThat(request.getLocalPort()).as("local port").isEqualTo(MockHttpServletRequest.DEFAULT_SERVER_PORT);
903+
// Remote port is always MockHttpServletRequest.DEFAULT_SERVER_PORT,
903904
// since a mocked request does not influence the remote host, port, or address.
904-
assertThat(request.getRemotePort()).as("remote port").isEqualTo(80);
905+
assertThat(request.getRemotePort()).as("remote port").isEqualTo(MockHttpServletRequest.DEFAULT_SERVER_PORT);
905906

906907
if (secure) {
907908
assertThat(request.isSecure()).as("secure").isTrue();

0 commit comments

Comments
 (0)