More accurate checks for presence of MediaType.ALL
Typically a straight up equals as well as Collections#contains checks for MediaType.ALL is susceptible to the presence of media type parameters. This commits adds equalsTypeAndSubtype as well as an isPresentIn(Collection<MimeType>) methods to MimeType to faciliate with checks for MediaType.ALL. Issue: SPR-17550
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -207,7 +207,7 @@ public final class ProducesRequestCondition extends AbstractRequestCondition<Pro
|
||||
if (!result.isEmpty()) {
|
||||
return new ProducesRequestCondition(result, this.contentNegotiationManager);
|
||||
}
|
||||
else if (acceptedMediaTypes.contains(MediaType.ALL)) {
|
||||
else if (MediaType.ALL.isPresentIn(acceptedMediaTypes)) {
|
||||
return EMPTY_CONDITION;
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -82,7 +82,8 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
|
||||
private static final Set<String> WHITELISTED_MEDIA_BASE_TYPES = new HashSet<>(
|
||||
Arrays.asList("audio", "image", "video"));
|
||||
|
||||
private static final MediaType MEDIA_TYPE_APPLICATION = new MediaType("application");
|
||||
private static final List<MediaType> ALL_APPLICATION_MEDIA_TYPES =
|
||||
Arrays.asList(MediaType.ALL, new MediaType("application"));
|
||||
|
||||
private static final Type RESOURCE_REGION_LIST_TYPE =
|
||||
new ParameterizedTypeReference<List<ResourceRegion>>() { }.getType();
|
||||
@@ -257,7 +258,7 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
|
||||
selectedMediaType = mediaType;
|
||||
break;
|
||||
}
|
||||
else if (mediaType.equals(MediaType.ALL) || mediaType.equals(MEDIA_TYPE_APPLICATION)) {
|
||||
else if (mediaType.isPresentIn(ALL_APPLICATION_MEDIA_TYPES)) {
|
||||
selectedMediaType = MediaType.APPLICATION_OCTET_STREAM;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user