SPR-7346 - @RequestHeader negation expressions (e.g. !Accept=text/plain) are not applied

git-svn-id: https://src.springframework.org/svn/spring-framework/trunk@3484 50f2f4bb-b051-0410-bef5-90022cba6387
This commit is contained in:
Arjen Poutsma
2010-07-15 08:49:18 +00:00
parent ef50421325
commit 4852217b79
3 changed files with 52 additions and 12 deletions
@@ -1315,7 +1315,24 @@ public class ServletAnnotationControllerTests {
servlet.service(request, response);
assertEquals("text", response.getContentAsString());
}
@Test
public void negatedContentTypeHeaders() throws ServletException, IOException {
initServlet(NegatedContentTypeHeadersController.class);
MockHttpServletRequest request = new MockHttpServletRequest("POST", "/something");
request.addHeader("Content-Type", "application/pdf");
MockHttpServletResponse response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("pdf", response.getContentAsString());
request = new MockHttpServletRequest("POST", "/something");
request.addHeader("Content-Type", "text/html");
response = new MockHttpServletResponse();
servlet.service(request, response);
assertEquals("non-pdf", response.getContentAsString());
}
@Test
public void acceptHeaders() throws ServletException, IOException {
initServlet(AcceptHeadersController.class);
@@ -2431,6 +2448,21 @@ public class ServletAnnotationControllerTests {
}
}
@Controller
public static class NegatedContentTypeHeadersController {
@RequestMapping(value = "/something", headers = "content-type=application/pdf")
public void handlePdf(Writer writer) throws IOException {
writer.write("pdf");
}
@RequestMapping(value = "/something", headers = "content-type!=application/pdf")
public void handleNonPdf(Writer writer) throws IOException {
writer.write("non-pdf");
}
}
@Controller
public static class AcceptHeadersController {