diff --git a/spring-web/src/main/java/org/springframework/http/server/reactive/TomcatHeadersAdapter.java b/spring-web/src/main/java/org/springframework/http/server/reactive/TomcatHeadersAdapter.java index 39f0a7f6c946..b5f37e7b3ca4 100644 --- a/spring-web/src/main/java/org/springframework/http/server/reactive/TomcatHeadersAdapter.java +++ b/spring-web/src/main/java/org/springframework/http/server/reactive/TomcatHeadersAdapter.java @@ -163,9 +163,7 @@ public void putAll(Map> map) { @Override public void clear() { - while (this.headers.size() > 0) { - this.headers.removeHeader(0); - } + this.headers.recycle(); } @Override diff --git a/spring-web/src/test/java/org/springframework/http/server/reactive/TomcatHeadersAdapterTests.java b/spring-web/src/test/java/org/springframework/http/server/reactive/TomcatHeadersAdapterTests.java index fc9480b1eebf..d54041c95119 100644 --- a/spring-web/src/test/java/org/springframework/http/server/reactive/TomcatHeadersAdapterTests.java +++ b/spring-web/src/test/java/org/springframework/http/server/reactive/TomcatHeadersAdapterTests.java @@ -25,17 +25,25 @@ * Tests for {@link TomcatHeadersAdapter}. * * @author Johnny Lim + * @author Sam Brannen + * @since 7.0 */ class TomcatHeadersAdapterTests { + private final TomcatHeadersAdapter adapter = new TomcatHeadersAdapter(new MimeHeaders()); + + @Test void clear() { - MimeHeaders mimeHeaders = new MimeHeaders(); - TomcatHeadersAdapter adapter = new TomcatHeadersAdapter(mimeHeaders); adapter.add("key1", "value1"); adapter.add("key2", "value2"); + assertThat(adapter).isNotEmpty(); + assertThat(adapter).hasSize(2); + assertThat(adapter).containsKeys("key1", "key2"); + adapter.clear(); assertThat(adapter).isEmpty(); + assertThat(adapter).hasSize(0); } }