Refine ContentNegotiationStrategy contract

Consistently return "*/*" if no media types were requested rather than
an empty list. Existing code has to check for both in any case to see
if nothing was requested.

Issue: SPR-16624
This commit is contained in:
Rossen Stoyanchev
2018-03-27 16:32:18 -04:00
parent 9a27bc9b3e
commit f3994467c4
11 changed files with 44 additions and 40 deletions

View File

@@ -259,8 +259,7 @@ public final class ProducesRequestCondition extends AbstractRequestCondition<Pro
}
private List<MediaType> getAcceptedMediaTypes(HttpServletRequest request) throws HttpMediaTypeNotAcceptableException {
List<MediaType> mediaTypes = this.contentNegotiationManager.resolveMediaTypes(new ServletWebRequest(request));
return mediaTypes.isEmpty() ? Collections.singletonList(MediaType.ALL) : mediaTypes;
return this.contentNegotiationManager.resolveMediaTypes(new ServletWebRequest(request));
}
private int indexOfEqualMediaType(MediaType mediaType) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -365,8 +365,7 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
private List<MediaType> getAcceptableMediaTypes(HttpServletRequest request)
throws HttpMediaTypeNotAcceptableException {
List<MediaType> types = this.contentNegotiationManager.resolveMediaTypes(new ServletWebRequest(request));
return (types.isEmpty() ? Collections.singletonList(MediaType.ALL) : types);
return this.contentNegotiationManager.resolveMediaTypes(new ServletWebRequest(request));
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -253,11 +253,7 @@ public class ContentNegotiatingViewResolver extends WebApplicationObjectSupport
Assert.state(this.contentNegotiationManager != null, "No ContentNegotiationManager set");
try {
ServletWebRequest webRequest = new ServletWebRequest(request);
List<MediaType> acceptableMediaTypes = this.contentNegotiationManager.resolveMediaTypes(webRequest);
acceptableMediaTypes = (!acceptableMediaTypes.isEmpty() ? acceptableMediaTypes :
Collections.singletonList(MediaType.ALL));
List<MediaType> producibleMediaTypes = getProducibleMediaTypes(request);
Set<MediaType> compatibleMediaTypes = new LinkedHashSet<>();
for (MediaType acceptable : acceptableMediaTypes) {