Whitelist extension if present in the request mapping
We know skip the Content-Disposition header for any extension if the chosen request mapping explicitly contains the URl extension. Issue: SPR-13629
This commit is contained in:
@@ -1711,6 +1711,32 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
assertArrayEquals(content, response.getContentAsByteArray());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void responseBodyAsTextWithCssExtension() throws Exception {
|
||||
initServlet(new ApplicationContextInitializer<GenericWebApplicationContext>() {
|
||||
@Override
|
||||
public void initialize(GenericWebApplicationContext wac) {
|
||||
ContentNegotiationManagerFactoryBean factoryBean = new ContentNegotiationManagerFactoryBean();
|
||||
factoryBean.afterPropertiesSet();
|
||||
RootBeanDefinition adapterDef = new RootBeanDefinition(RequestMappingHandlerAdapter.class);
|
||||
adapterDef.getPropertyValues().add("contentNegotiationManager", factoryBean.getObject());
|
||||
wac.registerBeanDefinition("handlerAdapter", adapterDef);
|
||||
}
|
||||
}, TextRestController.class);
|
||||
|
||||
byte[] content = "body".getBytes(Charset.forName("ISO-8859-1"));
|
||||
MockHttpServletRequest request = new MockHttpServletRequest("GET", "/a4.css");
|
||||
request.setContent(content);
|
||||
MockHttpServletResponse response = new MockHttpServletResponse();
|
||||
|
||||
getServlet().service(request, response);
|
||||
|
||||
assertEquals(200, response.getStatus());
|
||||
assertEquals("text/css", response.getContentType());
|
||||
assertNull(response.getHeader("Content-Disposition"));
|
||||
assertArrayEquals(content, response.getContentAsByteArray());
|
||||
}
|
||||
|
||||
/*
|
||||
* Controllers
|
||||
*/
|
||||
@@ -3187,6 +3213,11 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
|
||||
public String a3(@RequestBody String body) throws IOException {
|
||||
return body;
|
||||
}
|
||||
|
||||
@RequestMapping(path = "/a4.css", method = RequestMethod.GET)
|
||||
public String a4(@RequestBody String body) {
|
||||
return body;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user