Skip to content

Commit 6cf6d88

Browse files
committed
List OPTIONS in OPTIONS responses for @RequestMapping
Issue: SPR-16513
1 parent f7d60b7 commit 6cf6d88

File tree

5 files changed

+7
-5
lines changed

5 files changed

+7
-5
lines changed

spring-webflux/src/main/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMapping.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,7 @@ private static Set<HttpMethod> initAllowedHttpMethods(Set<HttpMethod> declaredMe
365365
if (result.contains(HttpMethod.GET)) {
366366
result.add(HttpMethod.HEAD);
367367
}
368+
result.add(HttpMethod.OPTIONS);
368369
return result;
369370
}
370371
}

spring-webflux/src/test/java/org/springframework/web/reactive/result/method/RequestMappingInfoHandlerMappingTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,8 @@ public void getHandlerHttpOptions() throws Exception {
195195
List<HttpMethod> allMethodExceptTrace = new ArrayList<>(Arrays.asList(HttpMethod.values()));
196196
allMethodExceptTrace.remove(HttpMethod.TRACE);
197197

198-
testHttpOptions("/foo", EnumSet.of(HttpMethod.GET, HttpMethod.HEAD));
199-
testHttpOptions("/person/1", EnumSet.of(HttpMethod.PUT));
198+
testHttpOptions("/foo", EnumSet.of(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.OPTIONS));
199+
testHttpOptions("/person/1", EnumSet.of(HttpMethod.PUT, HttpMethod.OPTIONS));
200200
testHttpOptions("/persons", EnumSet.copyOf(allMethodExceptTrace));
201201
testHttpOptions("/something", EnumSet.of(HttpMethod.PUT, HttpMethod.POST));
202202
}

spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMapping.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,7 @@ private static Set<HttpMethod> initAllowedHttpMethods(Set<String> declaredMethod
443443
result.add(HttpMethod.HEAD);
444444
}
445445
}
446+
result.add(HttpMethod.OPTIONS);
446447
}
447448
return result;
448449
}

spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/RequestMappingInfoHandlerMappingTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,8 @@ public void getHandlerMediaTypeNotSupported() throws Exception {
172172

173173
@Test
174174
public void getHandlerHttpOptions() throws Exception {
175-
testHttpOptions("/foo", "GET,HEAD");
176-
testHttpOptions("/person/1", "PUT");
175+
testHttpOptions("/foo", "GET,HEAD,OPTIONS");
176+
testHttpOptions("/person/1", "PUT,OPTIONS");
177177
testHttpOptions("/persons", "GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS");
178178
testHttpOptions("/something", "PUT,POST");
179179
}

spring-webmvc/src/test/java/org/springframework/web/servlet/mvc/method/annotation/ServletAnnotationControllerHandlerMethodTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1776,7 +1776,7 @@ public void httpOptions() throws Exception {
17761776
getServlet().service(request, response);
17771777

17781778
assertEquals(200, response.getStatus());
1779-
assertEquals("GET,HEAD", response.getHeader("Allow"));
1779+
assertEquals("GET,HEAD,OPTIONS", response.getHeader("Allow"));
17801780
assertTrue(response.getContentAsByteArray().length == 0);
17811781
}
17821782

0 commit comments

Comments
 (0)