Explicit HEAD sorted higher than implicit GET match

Issue: SPR-14182
This commit is contained in:
Rossen Stoyanchev
2016-04-17 15:12:43 -04:00
parent ff38224da6
commit 7cdcc102a9
3 changed files with 38 additions and 5 deletions

View File

@@ -53,7 +53,7 @@ public class RequestMethodsRequestConditionTests {
@Test
public void getMatchingConditionWithHttpHead() {
testMatch(new RequestMethodsRequestCondition(HEAD), HEAD);
testMatch(new RequestMethodsRequestCondition(GET), HEAD);
testMatch(new RequestMethodsRequestCondition(GET), GET);
testNoMatch(new RequestMethodsRequestCondition(POST), HEAD);
}

View File

@@ -1776,6 +1776,18 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
assertEquals("body", response.getContentAsString());
}
@Test
public void httpHeadExplicit() throws ServletException, IOException {
initServletWithControllers(ResponseEntityController.class);
MockHttpServletRequest request = new MockHttpServletRequest("HEAD", "/stores");
MockHttpServletResponse response = new MockHttpServletResponse();
getServlet().service(request, response);
assertEquals(200, response.getStatus());
assertEquals("v1", response.getHeader("h1"));
}
@Test
public void httpOptions() throws ServletException, IOException {
initServletWithControllers(ResponseEntityController.class);
@@ -3100,6 +3112,16 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
public ResponseEntity<String> baz() {
return ResponseEntity.ok().header("MyResponseHeader", "MyValue").body("body");
}
@RequestMapping(path = "/stores", method = RequestMethod.HEAD)
public ResponseEntity<Void> headResource() {
return ResponseEntity.ok().header("h1", "v1").build();
}
@RequestMapping(path = "/stores", method = RequestMethod.GET)
public ResponseEntity<String> getResource() {
return ResponseEntity.ok().body("body");
}
}
@Controller