Skip to content

Commit a603779

Browse files
committed
Return previous value in UndertowHeadersAdapter's remove() method
Prior to this commit, UndertowHeadersAdapter's remove() method violated the java.util.Map contract by always returning null. This commit fixes this by returning the previous list stored under the specified key, and otherwise returning null if no previous value was present. Closes gh-27592
1 parent e5475d6 commit a603779

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package org.springframework.http.server.reactive;
1818

1919
import java.util.AbstractSet;
20+
import java.util.ArrayList;
2021
import java.util.Collection;
2122
import java.util.Iterator;
2223
import java.util.List;
@@ -36,6 +37,7 @@
3637
* {@code MultiValueMap} implementation for wrapping Undertow HTTP headers.
3738
*
3839
* @author Brian Clozel
40+
* @author Sam Brannen
3941
* @since 5.1.1
4042
*/
4143
class UndertowHeadersAdapter implements MultiValueMap<String, String> {
@@ -131,7 +133,10 @@ public List<String> put(String key, List<String> value) {
131133
@Nullable
132134
public List<String> remove(Object key) {
133135
if (key instanceof String) {
134-
this.headers.remove((String) key);
136+
Collection<String> removed = this.headers.remove((String) key);
137+
if (removed != null) {
138+
return new ArrayList<>(removed);
139+
}
135140
}
136141
return null;
137142
}

0 commit comments

Comments
 (0)