Skip to content

Commit 657e002

Browse files
bivorstoyanchev
authored andcommitted
Fix HttpHeaders.setHost() to remove the header
See gh-33716
1 parent 9252e74 commit 657e002

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

spring-web/src/main/java/org/springframework/http/HttpHeaders.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,7 @@ public void setHost(@Nullable InetSocketAddress host) {
11361136
set(HOST, value);
11371137
}
11381138
else {
1139-
remove(HOST, null);
1139+
remove(HOST);
11401140
}
11411141
}
11421142

spring-web/src/test/java/org/springframework/http/HttpHeadersTests.java

+9
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,15 @@ void ipv6Host() {
213213
assertThat(headers.getFirst("Host")).as("Invalid Host header").isEqualTo("[::1]");
214214
}
215215

216+
@Test
217+
void hostDeletion() {
218+
InetSocketAddress host = InetSocketAddress.createUnresolved("localhost", 8080);
219+
headers.setHost(host);
220+
headers.setHost(null);
221+
assertThat(headers.getHost()).as("Host is not deleted").isEqualTo(null);
222+
assertThat(headers.getFirst("Host")).as("Host is not deleted").isEqualTo(null);
223+
}
224+
216225
@Test
217226
void eTagWithoutQuotes() {
218227
headers.setETag("v2.6");

0 commit comments

Comments
 (0)