Fix HeadersAdapters implementations

This commit harmonizes the `HeadersAdapter` implementations across all
supported servers with regards to the `get(Object key)` contract; some
server implementations are not sticking to a `Map`-like contract and
return empty `List` instead of `null` when a header is not present.

This also fixes the `size()` implementations to reflect the number of
header keys, as some implementations consider multiple values for the
same header as different entries.

Issue: SPR-17396
This commit is contained in:
Brian Clozel
2018-10-18 11:18:29 +02:00
parent fdaceeb6c9
commit ab8310b5f3
4 changed files with 103 additions and 4 deletions

View File

@@ -114,7 +114,7 @@ class JettyHeadersAdapter implements MultiValueMap<String, String> {
@Nullable
@Override
public List<String> get(Object key) {
if (key instanceof String) {
if (containsKey(key)) {
return this.headers.getValuesList((String) key);
}
return null;

View File

@@ -91,7 +91,7 @@ class NettyHeadersAdapter implements MultiValueMap<String, String> {
@Override
public int size() {
return this.headers.size();
return this.headers.names().size();
}
@Override
@@ -114,7 +114,7 @@ class NettyHeadersAdapter implements MultiValueMap<String, String> {
@Override
@Nullable
public List<String> get(Object key) {
if (key instanceof String) {
if (containsKey(key)) {
return this.headers.getAll((String) key);
}
return null;

View File

@@ -128,7 +128,7 @@ class TomcatHeadersAdapter implements MultiValueMap<String, String> {
@Override
@Nullable
public List<String> get(Object key) {
if (key instanceof String) {
if (containsKey(key)) {
return Collections.list(this.headers.values((String) key));
}
return null;