Expand range of whitelisted extensions by media type

This commit expands the range of whitelisted extensions by checking
if an extension can be resolved to image/*, audo/*, video/*, as well
as any content type that ends with +xml.

Issue: SPR-13643
This commit is contained in:
Rossen Stoyanchev
2015-11-05 19:31:03 -05:00
parent 237439ef97
commit a3168fde18
3 changed files with 62 additions and 2 deletions

View File

@@ -60,7 +60,17 @@ public abstract class AbstractMappingContentNegotiationStrategy
public List<MediaType> resolveMediaTypes(NativeWebRequest webRequest)
throws HttpMediaTypeNotAcceptableException {
String key = getMediaTypeKey(webRequest);
return resolveMediaTypeKey(webRequest, getMediaTypeKey(webRequest));
}
/**
* An alternative to {@link #resolveMediaTypes(NativeWebRequest)} that accepts
* an already extracted key.
* @since 3.2.16
*/
public List<MediaType> resolveMediaTypeKey(NativeWebRequest webRequest, String key)
throws HttpMediaTypeNotAcceptableException {
if (StringUtils.hasText(key)) {
MediaType mediaType = lookupMediaType(key);
if (mediaType != null) {

View File

@@ -88,6 +88,14 @@ public class ContentNegotiationManager implements ContentNegotiationStrategy,
}
/**
* Return the configured content negotiation strategies.
* @since 3.2.16
*/
public List<ContentNegotiationStrategy> getStrategies() {
return this.strategies;
}
/**
* Register more {@code MediaTypeFileExtensionResolver} instances in addition
* to those detected at construction.