Polish
This commit is contained in:
parent
c7bd3b8440
commit
e079a726f8
|
@ -485,7 +485,10 @@ public class ResourceHttpRequestHandler extends WebContentGenerator
|
|||
if (mediaType == null) {
|
||||
ServletWebRequest webRequest = new ServletWebRequest(request);
|
||||
try {
|
||||
getContentNegotiationManager().resolveMediaTypes(webRequest);
|
||||
List<MediaType> mediaTypes = getContentNegotiationManager().resolveMediaTypes(webRequest);
|
||||
if(!mediaTypes.isEmpty()) {
|
||||
mediaType = mediaTypes.get(0);
|
||||
}
|
||||
}
|
||||
catch (HttpMediaTypeNotAcceptableException ex) {
|
||||
// Ignore
|
||||
|
|
|
@ -54,6 +54,7 @@ import org.springframework.web.servlet.HandlerMapping;
|
|||
* @author Keith Donald
|
||||
* @author Jeremy Grelle
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Brian Clozel
|
||||
*/
|
||||
public class ResourceHttpRequestHandlerTests {
|
||||
|
||||
|
@ -244,6 +245,27 @@ public class ResourceHttpRequestHandlerTests {
|
|||
assertEquals("h1 { color:red; }", this.response.getContentAsString());
|
||||
}
|
||||
|
||||
@Test // SPR-13658
|
||||
public void getResourceWithRegisteredMediaTypeDefaultStrategy() throws Exception {
|
||||
ContentNegotiationManagerFactoryBean factory = new ContentNegotiationManagerFactoryBean();
|
||||
factory.setFavorPathExtension(false);
|
||||
factory.setDefaultContentType(new MediaType("foo", "bar"));
|
||||
factory.afterPropertiesSet();
|
||||
ContentNegotiationManager manager = factory.getObject();
|
||||
|
||||
List<Resource> paths = Collections.singletonList(new ClassPathResource("test/", getClass()));
|
||||
this.handler = new ResourceHttpRequestHandler();
|
||||
this.handler.setLocations(paths);
|
||||
this.handler.setContentNegotiationManager(manager);
|
||||
this.handler.afterPropertiesSet();
|
||||
|
||||
this.request.setAttribute(HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE, "foo.css");
|
||||
this.handler.handleRequest(this.request, this.response);
|
||||
|
||||
assertEquals("foo/bar", this.response.getContentType());
|
||||
assertEquals("h1 { color:red; }", this.response.getContentAsString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidPath() throws Exception {
|
||||
for (HttpMethod method : HttpMethod.values()) {
|
||||
|
|
Loading…
Reference in New Issue