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:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user