Retain entry set order in read-only HttpHeaders
Prior to this commit, the entry set of read-only HttpHeaders lost the
original headers' ordering.
The changes in commit ce7278aaf4 introduced a regression in the read-only
HttpHeaders support. Specifically, the implementation of entrySet() in
the internal ReadOnlyHttpHeaders class converted the original entry set
to an immutable, non-ordered set of immutable entries.
This commit fixes this issue by converting the original entry set to an
immutable, ordered set of immutable entries.
Closes gh-23551
This commit is contained in:
@@ -32,6 +32,7 @@ import java.util.EnumSet;
|
||||
import java.util.GregorianCalendar;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.TimeZone;
|
||||
|
||||
import org.hamcrest.Matchers;
|
||||
@@ -47,6 +48,7 @@ import static org.junit.Assert.*;
|
||||
* @author Sebastien Deleuze
|
||||
* @author Brian Clozel
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class HttpHeadersTests {
|
||||
|
||||
@@ -557,4 +559,20 @@ public class HttpHeadersTests {
|
||||
assertEquals("Bearer foo", authorization);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readOnlyHttpHeadersRetainEntrySetOrder() {
|
||||
headers.add("aardvark", "enigma");
|
||||
headers.add("beaver", "enigma");
|
||||
headers.add("cat", "enigma");
|
||||
headers.add("dog", "enigma");
|
||||
headers.add("elephant", "enigma");
|
||||
|
||||
String[] expectedKeys = new String[] { "aardvark", "beaver", "cat", "dog", "elephant" };
|
||||
|
||||
assertArrayEquals(expectedKeys, headers.entrySet().stream().map(Entry::getKey).toArray());
|
||||
|
||||
HttpHeaders readOnlyHttpHeaders = HttpHeaders.readOnlyHttpHeaders(headers);
|
||||
assertArrayEquals(expectedKeys, readOnlyHttpHeaders.entrySet().stream().map(Entry::getKey).toArray());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user