Skip to content

Commit

Permalink
Restore TomcatHeadersAdapter.clear() behavior
Browse files Browse the repository at this point in the history
This commit restores the original behavior of the clear() method in
TomcatHeadersAdapter by delegating to
org.apache.tomcat.util.http.MimeHeaders.recycle(), which aligns with
the memory efficiency goals documented in the class-level Javadoc for
MimeHeaders.

See gh-33916
Closes gh-34092
  • Loading branch information
sbrannen committed Dec 15, 2024
1 parent c8009dc commit 8a8df90
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,7 @@ public void putAll(Map<? extends String, ? extends List<String>> map) {

@Override
public void clear() {
while (this.headers.size() > 0) {
this.headers.removeHeader(0);
}
this.headers.recycle();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

}

0 comments on commit 8a8df90

Please sign in to comment.