Skip to content

Commit c8009dc

Browse files
izeyesbrannen
authored andcommitted
Fix TomcatHeadersAdapter.clear()
This commit fixes a regression introduced in TomcatHeadersAdapter in conjunction with gh-33916. Closes gh-34092
1 parent 5cbb5d4 commit c8009dc

File tree

2 files changed

+43
-2
lines changed

2 files changed

+43
-2
lines changed

spring-web/src/main/java/org/springframework/http/server/reactive/TomcatHeadersAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ public void putAll(Map<? extends String, ? extends List<String>> map) {
163163

164164
@Override
165165
public void clear() {
166-
for (int i = 0 ; i < this.headers.size(); i++) {
167-
this.headers.removeHeader(i);
166+
while (this.headers.size() > 0) {
167+
this.headers.removeHeader(0);
168168
}
169169
}
170170

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2002-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.http.server.reactive;
18+
19+
import org.apache.tomcat.util.http.MimeHeaders;
20+
import org.junit.jupiter.api.Test;
21+
22+
import static org.assertj.core.api.Assertions.assertThat;
23+
24+
/**
25+
* Tests for {@link TomcatHeadersAdapter}.
26+
*
27+
* @author Johnny Lim
28+
*/
29+
class TomcatHeadersAdapterTests {
30+
31+
@Test
32+
void clear() {
33+
MimeHeaders mimeHeaders = new MimeHeaders();
34+
TomcatHeadersAdapter adapter = new TomcatHeadersAdapter(mimeHeaders);
35+
adapter.add("key1", "value1");
36+
adapter.add("key2", "value2");
37+
adapter.clear();
38+
assertThat(adapter).isEmpty();
39+
}
40+
41+
}

0 commit comments

Comments
 (0)