Description
ayush-finix opened SPR-17598 and commented
Similar issue to #18266, however, disabling the cors processor doesn't work well enough.
We're building a proxy server where even the options requests should just be forwarded to the upstream, and the cors settings are somewhat interfering with this since there's CorsUtils.isPreflightRequest calls peppered around in various place (mostly referenced in the above ticket).
A few things I'd like to bring up:
After overriding RequestMappingHandlerMapping like
public class CorsNoopHandlerMapping extends RequestMappingHandlerMapping {
public CorsNoopHandlerMapping() {
setOrder(0); // Make it override the default handler mapping.
}
@Override
protected HandlerExecutionChain getCorsHandlerExecutionChain(HttpServletRequest request,
HandlerExecutionChain chain, CorsConfiguration config) {
return chain; // Return the same chain it uses for everything else.
}
}
in X extends WebMvcConfigurationSupport
@Override
protected RequestMappingHandlerMapping createRequestMappingHandlerMapping() {
return new CorsNoopHandlerMapping();
}
Disabling the cors processor and setting spring.mvc.dispatch-options-request=true still resolves a controller like the below to method 2
@RequestMapping(path = "/**", method = {RequestMethod.OPTIONS})
method1() {}
@RequestMapping(path = "/**", method = {RequestMethod.DELETE, RequestMethod.GET, RequestMethod.HEAD, RequestMethod.POST, RequestMethod.PATCH, RequestMethod.PUT, RequestMethod.TRACE})
method2() {}
because the default RequestMethodsRequestCondition still checks preflight requests
Aside: Why are all the condition classes final?
There's seems to be a lot of hoops to jump through to just make any OPTIONS call (with Origin header for example) resolve to something like method1, and it's really unfortunate that there's no sane way to override the CorsUtils methods or just disable the feature entirely. Sorry if this isn't the right place to discuss this, and please let me know if there's any more information necessary.
Affects: 5.1.2, 5.1.3
Issue Links:
- Enable/Disable Spring CORS option [SPR-13691] #18266 Enable/Disable Spring CORS option