List OPTIONS in OPTIONS responses for @RequestMapping

Issue: SPR-16513
This commit is contained in:
Rossen Stoyanchev 2018-05-14 08:59:12 -04:00
parent f7d60b7f58
commit 6cf6d8834c
5 changed files with 7 additions and 5 deletions

View File

@ -365,6 +365,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
if (result.contains(HttpMethod.GET)) {
result.add(HttpMethod.HEAD);
}
result.add(HttpMethod.OPTIONS);
return result;
}
}

View File

@ -195,8 +195,8 @@ public class RequestMappingInfoHandlerMappingTests {
List<HttpMethod> allMethodExceptTrace = new ArrayList<>(Arrays.asList(HttpMethod.values()));
allMethodExceptTrace.remove(HttpMethod.TRACE);
testHttpOptions("/foo", EnumSet.of(HttpMethod.GET, HttpMethod.HEAD));
testHttpOptions("/person/1", EnumSet.of(HttpMethod.PUT));
testHttpOptions("/foo", EnumSet.of(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.OPTIONS));
testHttpOptions("/person/1", EnumSet.of(HttpMethod.PUT, HttpMethod.OPTIONS));
testHttpOptions("/persons", EnumSet.copyOf(allMethodExceptTrace));
testHttpOptions("/something", EnumSet.of(HttpMethod.PUT, HttpMethod.POST));
}

View File

@ -443,6 +443,7 @@ public abstract class RequestMappingInfoHandlerMapping extends AbstractHandlerMe
result.add(HttpMethod.HEAD);
}
}
result.add(HttpMethod.OPTIONS);
}
return result;
}

View File

@ -172,8 +172,8 @@ public class RequestMappingInfoHandlerMappingTests {
@Test
public void getHandlerHttpOptions() throws Exception {
testHttpOptions("/foo", "GET,HEAD");
testHttpOptions("/person/1", "PUT");
testHttpOptions("/foo", "GET,HEAD,OPTIONS");
testHttpOptions("/person/1", "PUT,OPTIONS");
testHttpOptions("/persons", "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS");
testHttpOptions("/something", "PUT,POST");
}

View File

@ -1776,7 +1776,7 @@ public class ServletAnnotationControllerHandlerMethodTests extends AbstractServl
getServlet().service(request, response);
assertEquals(200, response.getStatus());
assertEquals("GET,HEAD", response.getHeader("Allow"));
assertEquals("GET,HEAD,OPTIONS", response.getHeader("Allow"));
assertTrue(response.getContentAsByteArray().length == 0);
}