diff --git a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java index 03338d2844..cb6dc3fc01 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfiguration.java @@ -653,7 +653,7 @@ public class WebMvcAutoConfiguration { Object skip = webRequest.getAttribute(SKIP_ATTRIBUTE, RequestAttributes.SCOPE_REQUEST); if (skip != null && Boolean.parseBoolean(skip.toString())) { - return Collections.emptyList(); + return MEDIA_TYPE_ALL_LIST; } return this.delegate.resolveMediaTypes(webRequest); } diff --git a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java index 365b2637b7..a024aab3f8 100644 --- a/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java +++ b/spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/web/servlet/WebMvcAutoConfigurationTests.java @@ -55,6 +55,7 @@ import org.springframework.core.io.Resource; import org.springframework.format.support.FormattingConversionService; import org.springframework.http.CacheControl; import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; import org.springframework.http.converter.HttpMessageConverter; import org.springframework.mock.web.MockHttpServletRequest; import org.springframework.test.util.ReflectionTestUtils; @@ -62,8 +63,11 @@ import org.springframework.util.StringUtils; import org.springframework.validation.Validator; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; import org.springframework.web.accept.ContentNegotiationManager; +import org.springframework.web.accept.ContentNegotiationStrategy; import org.springframework.web.accept.ParameterContentNegotiationStrategy; +import org.springframework.web.accept.PathExtensionContentNegotiationStrategy; import org.springframework.web.bind.support.ConfigurableWebBindingInitializer; +import org.springframework.web.context.request.ServletWebRequest; import org.springframework.web.filter.HttpPutFormContentFilter; import org.springframework.web.servlet.HandlerAdapter; import org.springframework.web.servlet.HandlerExceptionResolver; @@ -822,6 +826,20 @@ public class WebMvcAutoConfigurationTests { }); } + @Test + public void contentNegotiationStrategySkipsPathExtension() throws Exception { + ContentNegotiationStrategy delegate = mock(ContentNegotiationStrategy.class); + ContentNegotiationStrategy strategy = new WebMvcAutoConfiguration + .OptionalPathExtensionContentNegotiationStrategy(delegate); + + MockHttpServletRequest request = new MockHttpServletRequest(); + request.setAttribute(PathExtensionContentNegotiationStrategy.class + .getName() + ".SKIP", Boolean.TRUE); + ServletWebRequest webRequest = new ServletWebRequest(request); + List mediaTypes = strategy.resolveMediaTypes(webRequest); + assertThat(mediaTypes).containsOnly(MediaType.ALL); + } + private void assertCacheControl(AssertableWebApplicationContext context) { Map handlerMap = getHandlerMap( context.getBean("resourceHandlerMapping", HandlerMapping.class));