Refine CORS preflight requests handling with no configuration

This commit makes CORS preflight requests handling more flexible
by just skipping setting CORS response headers when no
configuration is defined instead of rejecting them.

That will have the same effect on user agent side (the preflight
request will be considered as not authorized and the actual
request not performed) but is more flexible and more efficient.

Closes gh-31839
This commit is contained in:
Sébastien Deleuze
2025-04-04 21:19:11 +02:00
parent 76d335aa41
commit eee45c3583
8 changed files with 45 additions and 54 deletions

View File

@@ -135,7 +135,9 @@ public class HandlerMethodMappingTests {
chain.getInterceptorList().get(0).preHandle(request, response, chain.getHandler());
new HttpRequestHandlerAdapter().handle(request, response, chain.getHandler());
assertThat(response.getStatus()).isEqualTo(403);
assertThat(response.getStatus()).isEqualTo(200);
assertThat(response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_ORIGIN)).isNull();
assertThat(response.getHeader(HttpHeaders.ACCESS_CONTROL_ALLOW_METHODS)).isNull();
}
@Test // gh-26490